Skip to content

Getting started

smtp-relay is an SMTP server that hands every email it receives to the outputs you configure: a local folder, the logs, another SMTP server, Amazon SES, S3 and SQS, or Google Cloud Storage and Pub/Sub. One configuration file describes everything; there is no default configuration.

The image is loopingz/smtp-relay on Docker Hub. Its working directory is /smtp-relay, it runs node lib/index.js and the first argument is the path of the configuration file. The sample files of the repository’s configs/ folder are in the image, under /smtp-relay/configs.

A debug inbox that writes every email it receives to a folder of your machine:

Terminal window
docker run -p 10025:10025 -v "$(pwd)/emails:/smtp-relay/received_emails" \
loopingz/smtp-relay:latest configs/fake-smtp-docker.jsonc

It uses this configuration:

configs/fake-smtp-docker.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",
// Docker subnet are usually on class b network
"subnets": ["172.16.0.0/12", "127.0.0.1/32"]
}
],
"outputs": [
{
"type": "file",
// Send store files in emails/
"path": "./received_emails/"
}
]
}
},
// Listen on every interface so the server is reachable from outside its container
"bind": "0.0.0.0",
"options": {
"disableReverseLookup": false,
// Do not require auth
"authOptional": true
}
}
  • The server listens on port 10025 (the default port).
  • "bind": "0.0.0.0" makes it listen on every interface. The default, localhost, only accepts connections from inside the container, so the published port would not reach it.
  • The whitelist filter accepts clients from 172.16.0.0/12 (the address range Docker usually gives its bridge networks) and 127.0.0.1. If your Docker network uses another range, the connection is refused: adjust subnets.
  • The file output writes each email to ./received_emails/, that is /smtp-relay/received_emails in the container, which the -v option maps to ./emails on your machine. Files are named ${iso8601}.eml by default (see path variables).

Point any SMTP client or application at localhost:10025 and the emails appear in ./emails.

Mount the file in the container and pass its path:

Terminal window
docker run -p 10025:10025 -v "$(pwd)/smtp-relay.jsonc:/smtp-relay/smtp-relay.jsonc" \
loopingz/smtp-relay:latest smtp-relay.jsonc

Always pass a configuration file. Without an argument the server reads ./smtp-relay.json, which the image does not contain, and stops.

Some values come from the environment: the static-auth filter reads SMTP_USERNAME, SMTP_PASSWORD and SMTP_PASSWORD_SALT when they are not in the file, the aws output uses the AWS SDK credential chain (AWS_ACCESS_KEY_ID, AWS_REGION, a container or instance role…) and the gcp output uses Google Application Default Credentials. For example, the sample with authentication:

Terminal window
docker run -e SMTP_USERNAME=test -e SMTP_PASSWORD=plain:test -p 10025:10025 \
-v "$(pwd)/emails:/smtp-relay/received_emails" \
loopingz/smtp-relay:latest configs/fake-smtp-with-auth.jsonc

smtp-relay needs Node.js 22.19 or later.

Terminal window
git clone https://github.com/loopingz/smtp-relay.git
cd smtp-relay
npm ci
npm run build
node lib/index.js configs/fake-smtp.jsonc

configs/fake-smtp.jsonc listens on localhost:10025, accepts clients from 127.0.0.1 and writes the emails to ./received_emails/.

The file is JSON (.json), JSON with comments (.jsonc) or YAML (.yml, .yaml); the extension selects the parser, and comments are accepted in .json files too. A configuration has three required parts:

  • $schema: the URL of the published schema, so editors validate and complete the file.
  • flows: the flows, each with its filters and outputs.
  • options: the server options (it can be empty).
smtp-relay.jsonc
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"inbox": {
"filters": [{ "type": "whitelist", "ips": ["127.0.0.1"] }],
"outputs": [{ "type": "file", "path": "./received_emails/" }]
}
},
"options": {
"authOptional": true
}
}

The same file in YAML:

smtp-relay.yaml
$schema: https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json
flows:
inbox:
filters:
- type: whitelist
ips: ["127.0.0.1"]
outputs:
- type: file
path: ./received_emails/
options:
authOptional: true

authOptional: true lets clients send without authenticating. Without it, clients must authenticate before MAIL FROM (see static-auth).

"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json"

main is the schema of the latest code. Replace it with a release tag, such as v3.1.4, to get the configuration format of that version. The server itself does not read this line.

  • Flows: how filters and outputs fit together.
  • Routing: what happens when an email has several recipients.
  • The filter and output pages, starting with whitelist and file.