Skip to content

Server options

Besides flows, the top level of the configuration sets where the server listens, how it stores emails while they are processed, and its metrics. The options object configures the SMTP server itself: it is passed to the smtp-server library, which smtp-relay is built on, together with its TLS options.

The server listens on port 10025 of localhost by default, so only programs on the same machine can reach it. Set bind to 0.0.0.0 (IPv4) or :: (IPv6 and IPv4) to listen on every interface, which is required in a container. The sample configurations meant for Docker do it.

Authentication is handled by smtp-server and decided by the AUTH filters of the flows (static-auth, http-auth).

  • authOptional: when true, clients may send without authenticating. When not set, a client must authenticate before MAIL FROM (530 Error: authentication Required otherwise).
  • allowInsecureAuth: allow AUTH on a connection that is not encrypted. Without it, the client must use TLS (secure or STARTTLS) before authenticating.
  • authMethods: the accepted methods, PLAIN and LOGIN by default.
  • disabledCommands: for example ["AUTH"] to turn authentication off.

Credentials are refused, with 535, only when no flow is left after the AUTH filters. An AND flow whose AUTH filter refuses them is dropped (its outputs do not run), but the session goes on through the other flows: an OR flow (a refusal does not drop it) or a flow without an AUTH filter lets any credentials through, the client gets 235 and can send through those flows. If no flow has an AUTH filter, any username and password are accepted. To require valid credentials, give every flow an AUTH filter with the default AND operator.

With secure: true the server expects TLS from the start of the connection; otherwise clients can upgrade with STARTTLS (hideSTARTTLS stops advertising it). Give the certificate with the TLS options, written directly in options: key, cert, ca and pfx accept PEM content or, as a string starting with file://, the path of a file to read.

Without key and cert, smtp-server uses its built-in self-signed certificate, whose private key is public: it logs a warning at startup. Provide your own certificate for anything but local tests.

TLS from the start of the connection
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"relay": {
"filters": [{ "type": "static-auth" }],
"outputs": [{ "type": "aws", "ses": true }]
}
},
"port": 465,
"bind": "0.0.0.0",
"options": {
"secure": true,
"key": "file:///etc/smtp-relay/tls.key",
"cert": "file:///etc/smtp-relay/tls.crt",
"minVersion": "TLSv1.2"
}
}

Each received email is first written to a file, cachePath, which the filters and outputs read. The file is deleted once the outputs have run, unless keepCache is true. The default, .email_${iso8601}_${id}.eml, is relative to the working directory; the folder is created if needed. See variables for the values available in the path.

mailHeaders changes the header block of every received email before it is written to cachePath, so every output sees the change. Each key is a header name:

  • "name": "value" adds the header;
  • "?name": "value" adds it only if the email does not have it;
  • "-name": "" removes every header of that name.

When mailHeaders is not set, smtp-relay adds x-smtp-relay: <version>. Setting it replaces that default.

Header changes
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"local": {
"filters": [{ "type": "whitelist", "ips": ["127.0.0.1"] }],
"outputs": [{ "type": "file", "path": "./received_emails/" }]
}
},
"mailHeaders": {
"X-Relayed-By": "smtp-relay",
"?Reply-To": "noreply@example.com",
"-X-Originating-IP": ""
},
"options": { "authOptional": true }
}

With prometheus, the server serves metrics over HTTP on prometheus.portNumber, at prometheus.url (/metrics by default). The counter smtp_relay_emails_total counts emails with the labels status (accepted per flow, rejected, or error per failed output), flow and output. nodeMetrics: true adds the Node.js process metrics.

Metrics on port 9090
$schema: https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json
flows:
local:
filters:
- type: whitelist
ips: ["127.0.0.1"]
outputs:
- type: log
prometheus:
portNumber: 9090
nodeMetrics: true
defaultLabels:
service: smtp-relay
options:
authOptional: true
OptionTypeDescription
$schemarequiredstring

URL of this JSON schema, so editors can validate and complete the configuration

bindstring
default "localhost"

Address the SMTP server listens on

The default only accepts connections from the local machine: set 0.0.0.0 (IPv4) or :: (IPv6 and IPv4) to listen on every network interface, e.g. when running in a container

cachePathstring
default ".email_${iso8601}_${id}.eml"

Path of the temporary file each received email is written to, its folder is created if needed

Variables written as ${name} are replaced: ${iso8601}, ${timestamp}, ${id}, ${from} and ${to}

filterTimeoutnumber
default 30000

Timeout in milliseconds for filter execution

flowsrequiredobject

Define email flows

flows.…object

Any other option of the underlying SDK or library is accepted

keepCacheboolean
default false

Keep the temporary email files of cachePath once processed instead of deleting them

mailHeadersobject
default {"x-smtp-relay":"current-version"}

Manipulate headers

mailHeaders.…string

Any other option of the underlying SDK or library is accepted

optionsrequiredobject

options defines the behavior of the server options.secure if true, the connection will use TLS. The default is false. If the server doesn’t start in TLS mode, it is still possible to upgrade clear text socket to TLS socket with the STARTTLS command (unless you disable support for it). If secure is true, additional tls options for tls.createServer can be added directly onto this options object. options.name optional hostname of the server, used for identifying to the client (defaults to os.hostname()) options.banner optional greeting message. This message is appended to the default ESMTP response. options.size optional maximum allowed message size in bytes, see details here options.hideSize if set to true then does not expose the max allowed size to the client but keeps size related values like stream.sizeExceeded options.authMethods optional array of allowed authentication methods, defaults to [‘PLAIN’, ‘LOGIN’]. Only the methods listed in this array are allowed, so if you set it to [‘XOAUTH2’] then PLAIN and LOGIN are not available. Use [‘PLAIN’, ‘LOGIN’, ‘XOAUTH2’] to allow all three. Authentication is only allowed in secure mode (either the server is started with secure:true option or STARTTLS command is used) options.authOptional allow authentication, but do not require it options.disabledCommands optional array of disabled commands (see all supported commands here). For example if you want to disable authentication, use [‘AUTH’] as this value. If you want to allow authentication in clear text, set it to [‘STARTTLS’]. options.hideSTARTTLS optional boolean, if set to true then allow using STARTTLS but do not advertise or require it. It only makes sense when creating integration test servers for testing the scenario where you want to try STARTTLS even when it is not advertised options.hidePIPELINING optional boolean, if set to true then does not show PIPELINING in feature list options.hide8BITMIME optional boolean, if set to true then does not show 8BITMIME in features list options.hideSMTPUTF8 optional boolean, if set to true then does not show SMTPUTF8 in features list options.allowInsecureAuth optional boolean, if set to true allows authentication even if connection is not secured first options.disableReverseLookup optional boolean, if set to true then does not try to reverse resolve client hostname options.sniOptions optional Map or an object of TLS options for SNI where servername is the key. Overrided by SNICallback. options.logger optional bunyan compatible logger instance. If set to true then logs to console. If value is not set or is false then nothing is logged options.maxClients sets the maximum number of concurrently connected clients, defaults to Infinity options.useProxy boolean, if set to true expects to be behind a proxy that emits a PROXY header (version 1 only) options.useXClient boolean, if set to true, enables usage of XCLIENT extension to override connection properties. See session.xClient (Map object) for the details provided by the client options.useXForward boolean, if set to true, enables usage of XFORWARD extension. See session.xForward (Map object) for the details provided by the client options.lmtp boolean, if set to true use LMTP protocol instead of SMTP options.socketTimeout how many milliseconds of inactivity to allow before disconnecting the client (defaults to 1 minute) options.closeTimeout how many milliseconds to wait before disconnecting pending connections once server.close() has been called (defaults to 30 seconds)

options.ALPNProtocolsstring[]

Possible ALPN protocols, ordered by priority

options.allowHalfOpenboolean
default false

Allow half-opened TCP connections

options.allowInsecureAuthboolean

optional boolean, if set to true allows authentication even if connection is not secured first

options.allowPartialTrustChainboolean

Treat intermediate (non-self-signed) certificates of the trusted CA list as trusted

options.authMethodsstring[]

optional array of allowed authentication methods, defaults to ['PLAIN', 'LOGIN']. Only the methods listed in this array are allowed, so if you set it to ['XOAUTH2'] then PLAIN and LOGIN are not available. Use ['PLAIN', 'LOGIN', 'XOAUTH2'] to allow all three. Authentication is only allowed in secure mode (either the server is started with secure: true option or STARTTLS command is used)

options.authOptionalboolean

allow authentication, but do not require it

options.bannerstring

optional greeting message. This message is appended to the default ESMTP response.

options.castring | string[]

PEM encoded CA certificates to trust instead of the default ones, a string starting with file:// is read from that file

options.certstring | string[]

PEM encoded certificate chain(s), a string starting with file:// is read from that file

options.ciphersstring

Cipher suite specification, replacing the default

options.closeTimeoutnumber

How many millisceonds to wait before disconnecting pending connections once server.close() has been called (defaults to 30 seconds)

options.crlstring | string[]

PEM encoded certificate revocation lists

options.dhparamstring

auto or PEM encoded Diffie-Hellman parameters, required for non-ECDHE perfect forward secrecy

options.disableReverseLookupboolean

optional boolean, if set to true then does not try to reverse resolve client hostname

options.disabledCommandsstring[]

optional array of disabled commands (see all supported commands here). For example if you want to disable authentication, use ['AUTH'] as this value. If you want to allow authentication in clear text, set it to ['STARTTLS'].

options.ecdhCurvestring

Named curve or colon separated list of curves for ECDH key agreement, auto to select it automatically

options.enableTraceboolean
default false

Write TLS packet trace information to stderr

options.handshakeTimeoutnumber
default 120000

Abort the connection if the TLS handshake does not finish within this many milliseconds

options.hide8BITMIMEboolean

optional boolean, if set to true then does not show 8BITMIME in features list

options.hidePIPELININGboolean

optional boolean, if set to true then does not show PIPELINING in feature list

options.hideSMTPUTF8boolean

optional boolean, if set to true then does not show SMTPUTF8 in features list

options.hideSTARTTLSboolean

optional boolean, if set to true then allow using STARTTLS but do not advertise or require it. It only makes sense when creating integration test servers for testing the scenario where you want to try STARTTLS even when it is not advertised

options.highWaterMarknumber

Readable and writable high water mark of the sockets, in bytes

options.honorCipherOrderboolean

Use the cipher suite preferences of the server instead of those of the client

options.keepAliveboolean
default false

Enable keep-alive on incoming connections

options.keepAliveInitialDelaynumber
default 0

Initial delay in milliseconds before the first keep-alive probe

options.keystring | (string | object)[]

PEM encoded private key(s), a string starting with file:// is read from that file

options.lmtpboolean

if set to true use LMTP protocol instead of SMTP

options.loggersobject[]
default [{"type":"CONSOLE"}]

Where to write the logs

options.maxClientsnumber

sets the maximum number of concurrently connected clients, defaults to Infinity

options.maxVersion"TLSv1.3" | "TLSv1.2" | "TLSv1.1" | "TLSv1"

Maximum TLS version to allow

options.minVersion"TLSv1.3" | "TLSv1.2" | "TLSv1.1" | "TLSv1"

Minimum TLS version to allow

options.namestring

optional hostname of the server, used for identifying to the client (defaults to os.hostname())

options.noDelayboolean
default false

Disable Nagle's algorithm on incoming connections

options.passphrasestring

Passphrase of the private key or of the PFX

options.pauseOnConnectboolean
default false

Pause the socket on incoming connections

options.pfxstring | (string | object)[]

PFX or PKCS12 encoded private key and certificate chain, an alternative to key and cert, a string starting with file:// is read from that file

options.pskIdentityHintstring

Hint sent to the client to select the identity during TLS-PSK negotiation, ignored in TLS 1.3

options.rejectUnauthorizedboolean
default true

With requestCert, reject the clients whose certificate is not signed by a trusted CA

options.requestCertboolean
default false

Request a certificate from the clients

options.secureboolean

if true, the connection will use TLS. The default is false. If the server doesn't start in TLS mode, it is still possible to upgrade clear text socket to TLS socket with the STARTTLS command (unless you disable support for it). If secure is true, additional tls options for tls. createServer can be added directly onto this options object.

options.secureOptionsnumber

Bitmask of the SSL_OP_* options from OpenSSL

options.secureProtocolstring

Legacy selection of the TLS protocol version, e.g. TLS_method, prefer minVersion and maxVersion

options.sessionIdContextstring

Opaque identifier so session state is not shared between applications

options.sessionTimeoutnumber
default 300

Seconds after which a TLS session is no longer resumable

options.sigalgsstring

Colon separated list of supported signature algorithms

options.sizenumber

optional maximum allowed message size in bytes (see details)

options.socketTimeoutnumber

How many milliseconds of inactivity to allow before disconnecting the client (defaults to 1 minute)

options.useProxyboolean | string[]

if set to true expects to be behind a proxy that emits a PROXY header (version 1 only), an array lists the proxy addresses the header is expected from

options.useXClientboolean | string[]

if set to true, enables usage of XCLIENT extension to override connection properties, an array lists the client addresses allowed to use it. See session.xClient (Map object) for the details provided by the client

options.useXForwardboolean | string[]

if set to true, enables usage of XFORWARD extension, an array lists the client addresses allowed to use it. See session.xForward (Map object) for the details provided by the client

portnumber
default 10025

Port the SMTP server listens on

prometheusobject

Configure prometheus metrics

prometheus.bindstring

Bind to a specific address

prometheus.defaultLabelsobject

Default labels to add to prometheus

prometheus.nodeMetricsboolean

Collect node metrics

prometheus.portNumberrequirednumber

Port to bind to serve prometheus metrics

prometheus.urlstring
default "/metrics"

Url to use