ScriptsMay 16, 2026·3 min read

Nodemailer — Send Emails from Node.js with Ease

The de facto email sending library for Node.js, supporting SMTP, OAuth2, HTML templates, and attachments with a simple unified API.

Agent ready

This asset can be read and installed directly by agents

TokRepo exposes a universal CLI command, install contract, metadata JSON, adapter-aware plan, and raw content links so agents can judge fit, risk, and next actions.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
Nodemailer Overview
Universal CLI install command
npx tokrepo install a11d7b90-50fe-11f1-9bc6-00163e2b0d79

Introduction

Nodemailer is the most widely used email sending module for Node.js, handling SMTP connections, authentication, and message composition. It abstracts away transport complexities so developers can send transactional emails, notifications, and reports with minimal configuration.

What Nodemailer Does

  • Connects to any SMTP server with support for STARTTLS, direct TLS, and custom ports
  • Sends HTML and plain-text emails with inline images, attachments, and embedded CID references
  • Supports OAuth2 authentication for Gmail, Outlook, and other providers
  • Provides connection pooling for high-throughput email delivery
  • Includes a built-in test account generator via Ethereal for development and CI

Architecture Overview

Nodemailer separates concerns into transports and message composition. The transport layer manages TCP connections, TLS negotiation, and SMTP command sequences. The message layer handles MIME multipart construction, header encoding, and attachment streaming. Plugins can intercept the message pipeline to add DKIM signatures, transform HTML to text, or log outgoing messages.

Self-Hosting & Configuration

  • Install from npm with zero native dependencies — pure JavaScript
  • Configure transports via an options object or a connection URL string
  • Enable connection pooling with pool: true for batch sends
  • Use nodemailer.createTestAccount() to get disposable Ethereal credentials during development
  • Add DKIM signing by passing dkim options with domain, key selector, and private key

Key Features

  • Unicode-safe — handles international email addresses and encoded headers
  • Stream-based attachments for sending large files without buffering in memory
  • Calendar event support via iCalendar (ICS) attachments with method headers
  • Proxy support including SOCKS4/5 and HTTP CONNECT for restricted networks
  • Over 17,500 GitHub stars and 8 million weekly npm downloads

Comparison with Similar Tools

  • SendGrid SDK — managed delivery with analytics; Nodemailer works with any SMTP provider directly
  • AWS SES SDK — vendor-locked to Amazon; Nodemailer is transport-agnostic
  • Resend — modern API-first service; Nodemailer gives full SMTP control and offline testing
  • email.js — browser-side email via SMTP.js proxy; Nodemailer runs server-side with full auth
  • Postal — self-hosted mail server; Nodemailer is a client library, not a server

FAQ

Q: Does Nodemailer work with Gmail? A: Yes. Use OAuth2 credentials or an App Password. Gmail rate-limits free accounts to around 500 emails per day.

Q: Can I send bulk emails with Nodemailer? A: It supports connection pooling for throughput, but for large campaigns consider a dedicated service with bounce handling and reputation management.

Q: How do I test emails locally without a real SMTP server? A: Use nodemailer.createTestAccount() to get Ethereal credentials, then view sent messages in the Ethereal web interface.

Q: Is it compatible with ESM and TypeScript? A: Yes. Nodemailer ships CommonJS with bundled TypeScript declarations. Import via import nodemailer from 'nodemailer' with appropriate module settings.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets