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.
Run it with Docker
Section titled “Run it with Docker”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:
docker run -p 10025:10025 -v "$(pwd)/emails:/smtp-relay/received_emails" \ loopingz/smtp-relay:latest configs/fake-smtp-docker.jsoncIt uses this configuration:
// 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 defaultport). "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
whitelistfilter accepts clients from172.16.0.0/12(the address range Docker usually gives its bridge networks) and127.0.0.1. If your Docker network uses another range, the connection is refused: adjustsubnets. - The
fileoutput writes each email to./received_emails/, that is/smtp-relay/received_emailsin the container, which the-voption maps to./emailson your machine. Files are named${iso8601}.emlby default (see path variables).
Point any SMTP client or application at localhost:10025 and the emails appear in ./emails.
Use your own configuration
Section titled “Use your own configuration”Mount the file in the container and pass its path:
docker run -p 10025:10025 -v "$(pwd)/smtp-relay.jsonc:/smtp-relay/smtp-relay.jsonc" \ loopingz/smtp-relay:latest smtp-relay.jsoncAlways 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:
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.jsoncRun it from a clone
Section titled “Run it from a clone”smtp-relay needs Node.js 22.19 or later.
git clone https://github.com/loopingz/smtp-relay.gitcd smtp-relaynpm cinpm run buildnode lib/index.js configs/fake-smtp.jsoncconfigs/fake-smtp.jsonc listens on localhost:10025, accepts clients from 127.0.0.1 and writes the emails to
./received_emails/.
The configuration file
Section titled “The configuration file”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).
{ "$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:
$schema: https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.jsonflows: inbox: filters: - type: whitelist ips: ["127.0.0.1"] outputs: - type: file path: ./received_emails/options: authOptional: trueauthOptional: true lets clients send without authenticating. Without it, clients must authenticate before
MAIL FROM (see static-auth).
The $schema line
Section titled “The $schema line”"$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.