Nodemailer
Send emails from Node.js - easy as cake! ✉️
Nodemailer is the most popular email sending library for Node.js. It makes sending emails straightforward and secure, with zero runtime dependencies to manage.
npm install nodemailer
EmailEngine is a self-hosted email gateway that provides REST API access to IMAP and SMTP accounts, webhooks for mailbox changes, and advanced features like OAuth2, delayed delivery, open and click tracking, bounce detection, and more.
Why Nodemailer?
- Zero runtime dependencies - everything you need is included in a single, well-maintained package.
- Security focused - designed to avoid remote code execution vulnerabilities that have affected other Node.js email libraries.
- Full Unicode support - send messages with any characters, including emoji 💪.
- Cross-platform - works identically on Linux, macOS, and Windows with no native addons required (ideal for cloud environments like Azure).
- HTML and plain-text emails - send rich HTML emails with automatic plain-text fallbacks.
- Attachments and embedded images - easily include files and inline images in your messages.
- Built-in TLS/STARTTLS encryption - secure connections are handled automatically.
- Multiple transports - send via SMTP, Sendmail, Amazon SES, streams, and more.
- DKIM signing and OAuth2 authentication - enterprise-ready email authentication.
- Proxy support - route email through proxies for restricted network environments.
- Plugin API - extend functionality with custom plugins for advanced message processing.
- Ethereal.email integration - generate test accounts instantly for local development and testing.
Requirements
- Node.js v6.0.0 or later (examples using async/await require Node.js v8.0.0 or later).
No additional system libraries, services, or build tools are needed.
Quick Start
Sending an email with Nodemailer involves three simple steps:
- Create a transporter - Configure your SMTP server or another supported transport method.
- Compose your message - Define the sender, recipient(s), subject, and content.
- Send the email - Call
transporter.sendMail()with your message options.
Example: Sending an Email with Ethereal
Ethereal is a free service that captures outgoing emails for testing. No emails are actually delivered, making it perfect for development.
const nodemailer = require("nodemailer");
// Create a transporter using Ethereal test credentials.
// For production, replace with your actual SMTP server details.
const transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false, // Use true for port 465, false for port 587
auth: {
user: "[email protected]",
pass: "jn7jnAPss4f63QBp6D",
},
});
// Send an email using async/await
(async () => {
const info = await transporter.sendMail({
from: '"Maddison Foo Koch" <[email protected]>',
to: "[email protected], [email protected]",
subject: "Hello ✔",
text: "Hello world?", // Plain-text version of the message
html: "<b>Hello world?</b>", // HTML version of the message
});
console.log("Message sent:", info.messageId);
})();
Ethereal provides a preview URL for every message sent, allowing you to view the rendered email in your browser. This is invaluable for testing email layouts and content during development.
Source and License
Nodemailer is open source software, licensed under the MIT No Attribution (MIT-0) license. This means you can use it freely in any project without attribution requirements. Browse the source code on GitHub.
Made with ❤️ by Andris Reinman. Logo by Sven Kristjansen.