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: truefor batch sends - Use
nodemailer.createTestAccount()to get disposable Ethereal credentials during development - Add DKIM signing by passing
dkimoptions 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.