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:Configuring the transport
Create a Nodemailer transporter withmailchannelsTransport(), imported from mailchannels-sdk/nodemailer:
Sending mail
Once configured, send mail through Nodemailer’s standardsendMail(). No MailChannels-specific code is required for a
basic send:
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 themailchannels 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’sdkim message option is passed to MailChannels, which signs the message on your behalf. Supply a single
signature with domainName, keySelector, and privateKey:
Reading the result
sendMail() resolves with Nodemailer’s usual info object. What it contains depends on sendMode:
- Synchronous send (
sendMode: 'sync'):messageIdis the ID MailChannels assigned, and every recipient appears inacceptedorrejecteddepending on the send result. - Queued (default): the API doesn’t return a message ID per call, so
messageIdisnulland bothacceptedandrejectedare empty. Delivery status arrives later through webhooks.
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: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
replyTois 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
MailChannelsclient 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.

