Skip to main content

Other transports

Nodemailer includes a fully-featured SMTP transport that is enabled by default, but you are not limited to SMTP. A transport is the mechanism Nodemailer uses to deliver a fully-constructed email message. This could involve piping the message to the local sendmail binary, posting it to an HTTPS API like Amazon SES, or using any other delivery method you choose.

This page lists the transports bundled with Nodemailer as well as popular community-maintained transports. If none of these fit your needs, you can create your own by following the transport API documentation.


Example: Amazon SES transport

The following example shows how to send email through Amazon SES using the built-in SES transport. This transport uses the official AWS SDK v3 client to communicate with the SES API.

Install dependencies
npm install nodemailer @aws-sdk/client-sesv2
send-with-ses.js
const nodemailer = require("nodemailer");
const { SESv2Client, SendEmailCommand } = require("@aws-sdk/client-sesv2");

// Create an SES client. Configure your AWS credentials and region
// using environment variables, shared credentials file, or IAM roles.
const sesClient = new SESv2Client({});

// Create a Nodemailer transporter that uses the SES client.
// The property must be named "SES" (case-sensitive) and must include
// both the sesClient instance and the SendEmailCommand class.
const transporter = nodemailer.createTransport({
SES: { sesClient, SendEmailCommand },
});

// Send an email using the standard Nodemailer sendMail interface
(async () => {
await transporter.sendMail({
from: "you@example.com",
to: "friend@example.net",
subject: "Hello from SES",
text: "This message was sent with Nodemailer and Amazon SES!",
});
})();

Available transports

Bundled (built-in) transports

These transports are included with Nodemailer and require no additional packages.

TransportPurposeReference
SMTPThe default transport. Connects to an SMTP server to deliver messages.Docs
sendmailPipes the generated message to a local sendmail-compatible binary on your server.Docs
SESSends mail through the Amazon SES API using the AWS SDK v3.Docs
streamReturns the generated RFC 5322 message as a stream instead of sending it. Useful for testing or custom processing.Docs

Community transports

These transports are maintained by the community in separate npm packages. Install them with npm install and pass their exported function to nodemailer.createTransport().

  • Mailtrap - Deliver messages to your Mailtrap inbox for safe email testing without sending to real recipients (npm)
  • Mailgun - Send email through Mailgun's HTTP API (npm)
  • Custom - Build your own transport to implement business-specific logic. See creating custom transports.
note

Third-party transports are not maintained by the Nodemailer team. Check each project's README for installation instructions and usage details.


Transport-agnostic options

While each transport has its own configuration options, the following options work with all transports. Set these options on the configuration object you pass to createTransport().

OptionTypeDescription
attachDataUrlsBooleanWhen set to true, Nodemailer automatically converts inline data: URIs found in HTML content into embedded attachments. This is useful when your HTML contains base64-encoded images.
disableFileAccessBooleanWhen set to true, prevents Nodemailer from reading files from the filesystem when resolving attachments or HTML images. Enable this option when processing untrusted message content for security.
disableUrlAccessBooleanWhen set to true, prevents Nodemailer from making HTTP/HTTPS requests when resolving attachments or HTML images referenced by URL. Enable this option when processing untrusted message content for security.
normalizeHeaderKey(key)FunctionA callback function invoked for each header key before the header is added to the generated RFC 5322 message. Use this to customize header formatting. Example