Skip to content

nodemailer

The nodemailer output sends each email through an SMTP server with the nodemailer library: your provider’s relay, a company mail server, Gmail, or another smtp-relay.

The email is rebuilt from the parsed message: From, To and Cc headers, subject, text and HTML bodies, and attachments. The other headers of the received email are not forwarded; nodemailer writes its own (Date, Message-ID…).

It is delivered to the recipients the flow accepted (RCPT TO), including blind copies, and not to the To and Cc headers: two flows that split the recipients of one email each deliver only to their own. The envelope sender is the address of the received From header, even when override changes from.

override forces message fields on every email, for example a fixed from or extra headers. When override sets to, cc, bcc or envelope, it takes over the delivery: nodemailer then sends to the recipients those fields give, not to the flow’s.

dkims holds one signing key per sender domain. The domain of the envelope sender (MAIL FROM) selects the entry; emails from other domains are sent unsigned. The DKIM guide shows how to create a key and publish it.

  • Relay the emails of applications that only speak SMTP to a provider that needs authentication or TLS, keeping the credentials in one place.
  • Sign outgoing emails with DKIM.
  • Forward emails to another SMTP server while storing a copy with another output.
OptionTypeDescription
dkimsobject

DKIM signing configuration per sender domain, the domain of the envelope sender (MAIL FROM) selects the entry, emails of other domains are not signed

dkims.…object

Any other option of the underlying SDK or library is accepted

namestring

Name of the component, used in the logs and the output metrics, defaults to <type>_<position in the list>

nodemailerstring | object

Nodemailer SMTP transport: a connection URL (e.g. smtps://user:pass@smtp.example.com) or the transport options

overrideobject

Message fields to force on every email

dkim is not part of it, use the dkims attribute instead

override.bccstring | object | (string | object)[]

Bcc recipients

override.ccstring | object | (string | object)[]

Recipients of the Cc header, replaces those of the received email

override.envelopeobject

SMTP envelope to use instead of the one generated from the headers

override.fromstring | object

Sender address, replaces the From header of the received email

override.headersobject

Extra headers to add, header name as key

override.htmlstring

HTML body, replaces the received one

override.inReplyTostring

Message-ID this email replies to, for the In-Reply-To header

override.priority"high" | "normal" | "low"

Priority of the email, sets the priority headers

override.referencesstring | string[]

Message-IDs for the References header

override.replyTostring | object | (string | object)[]

Addresses for the Reply-To header

override.senderstring | object

Address for the Sender header

override.subjectstring

Subject of the email, replaces the received one

override.textstring

Plain text body, replaces the received one

override.tostring | object | (string | object)[]

Recipients of the To header, replaces those of the received email

override.xMailerstring | false

Value of the X-Mailer header, false leaves the header out

override.…any

Any other option of the underlying SDK or library is accepted

typerequired"nodemailer"

Type of the component

Forward emails from the local machine to another SMTP server on localhost:10026 (for example a second smtp-relay running fake-smtp-log.jsonc):

configs/nodemailer.jsonc
// Can replace fakeSMTP.jar
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"localhost": {
"filters": [
// Allow only localhost
{
"type": "whitelist",
"ips": ["127.0.0.1"]
}
],
"outputs": [
{
// We just log to the console
"type": "nodemailer",
"nodemailer": {
"host": "localhost",
"port": 10026,
"secure": false,
"auth": {
"user": "user",
"pass": "pass"
},
"tls": {
"rejectUnauthorized": false
}
}
}
]
}
},
"options": {
"disableReverseLookup": false,
// Do not require auth
"authOptional": true
}
}

Send through a provider with a connection URL, sign the emails of example.com, and add a header:

nodemailer-dkim.jsonc
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"outgoing": {
"filters": [{ "type": "whitelist", "subnets": ["10.0.0.0/8"], "from": ["regexp:.*@example.com"] }],
"outputs": [
{
"type": "nodemailer",
"nodemailer": "smtps://relay-user:relay-password@smtp.provider.example:465",
"override": { "headers": { "X-Relayed-By": "smtp-relay" } },
"dkims": {
"example.com": {
"keySelector": "default",
"privateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvQ...\n-----END PRIVATE KEY-----\n"
}
}
}
]
}
},
"bind": "0.0.0.0",
"options": { "authOptional": true }
}