Skip to main content
The mailchannels-sdk package ships a Nodemailer transport. If you already have a Node.js application that composes messages with Nodemailer, you can switch to MailChannels by swapping the transport and leaving the rest of your code alone.
This transport is optional and lives alongside the rest of the JavaScript SDK. It requires the nodemailer package, which the SDK does not install for you. The transport itself can only send mail. It doesn’t implement the full API surface (sub-accounts, keys, webhooks, etc.). For those features, use the SDK’s MailChannels client directly.

Prerequisites

Before you send your first message, follow the JavaScript quickstart prerequisite section. This will walk you through creating an account, generating an API key, and adding the required DNS records.

Installation

Install the SDK and Nodemailer:
The transport requires Node.js 20 or later, the same as the SDK.

Configuring the transport

Create a Nodemailer transporter with mailchannelsTransport(), imported from mailchannels-sdk/nodemailer:
The transport accepts the following options:

Sending mail

Once configured, send mail through Nodemailer’s standard sendMail(). No MailChannels-specific code is required for a basic send:
See Nodemailer’s docs on message configuration for everything else sendMail() accepts. The transport maps from, to, cc, bcc, replyTo, subject, text, html, headers, attachments, icalEvent, and dkim onto the corresponding Email API fields.
Every address in to, cc, and bcc receives the same message. If you need to send multiple individualized emails in one request, call the SDK’s MailChannels client directly instead of going through Nodemailer. See How emails are structured for more information on personalizations.

MailChannels options

Nodemailer’s message object has no equivalent for some MailChannels API features. Reach those instead through the mailchannels field on the sendMail() options. The SDK augments Nodemailer’s types, so these are type-checked in TypeScript projects:
Each of these corresponds directly to a field on the send endpoint. See that reference for full semantics.

DKIM

Nodemailer’s dkim message option is passed to MailChannels, which signs the message on your behalf. Supply a single signature with domainName, keySelector, and privateKey:
Use an RSA private key; 2048 bits is recommended. Every mailbox provider can verify RSA signatures, and RSA is the key type MailChannels can validate when checking your domain’s DKIM setup. Nodemailer’s multi-signature dkim.keys form is rejected. A privateKey given as a { key, passphrase } object is decrypted and converted to PEM before sending.See DKIM signing and key management for information on how MailChannels handles signing and keys.

Reading the result

sendMail() resolves with Nodemailer’s usual info object. What it contains depends on sendMode:
  • Synchronous send (sendMode: 'sync'): messageId is the ID MailChannels assigned, and every recipient appears in accepted or rejected depending on the send result.
  • Queued (default): the API doesn’t return a message ID per call, so messageId is null and both accepted and rejected are empty. Delivery status arrives later through webhooks.
In both modes, info.response holds the raw SDK response.

Error handling

Any SDK error raised while sending (authentication, validation, rate limiting, server errors) is surfaced as a rejected promise carrying the API’s error message:
To inspect the original API error, pass a callback instead. The info argument is still populated on failure, and info.response.error carries the error’s type, statusCode, and message:
A missing apiKey is reported when the transport is created, not when you send. mailchannelsTransport() throws Missing MailChannels API key. immediately.

Limitations

  • One message per call. Every recipient gets the same content; there is no per-recipient template data or header override through this transport.
  • Single reply-to address. If replyTo is an array, only the first address is used.
  • DKIM only via the MailChannels API, as described above.
  • No Mustache templating. This transport has no way to use MailChannels’ Mustache template rendering. Use the SDK’s MailChannels client directly; see Templates for how.

Next steps

  • Read the webhooks guide to learn how to get real-time notifications about email delivery, bounces, and complaints.
  • Explore the API reference to see what else you can do with the API.