Replacing aws-smtp-relay
smtp-relay replaces aws-smtp-relay, the earlier project that received SMTP and sent each email with the
Amazon SES API. The same job is one flow with an aws output and "ses": true; the
applications keep sending SMTP to port 10025.
Start it
Section titled “Start it”The image contains a ready configuration:
docker run -p 10025:10025 -e AWS_REGION=us-east-1 loopingz/smtp-relay:latest configs/aws-smtp-relay.jsonc// Replace my previous project aws-smtp-relay{ "$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json", "flows": { "localhost": { "filters": [ // Allow any ip to use the SMTP { "type": "whitelist", "ips": ["regexp:.*"] } ], "outputs": [ { "type": "aws", // Send it to SES "ses": true } ] } }, // Listen on every interface so the server is reachable from outside its container "bind": "0.0.0.0", "options": { "disableReverseLookup": false, "hideSTARTTLS": true, // Do not require auth "authOptional": true }}- Credentials come from the AWS SDK default chain: the role of the ECS task, EKS pod (IRSA or Pod Identity) or EC2
instance, or
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. The identity needsses:SendRawEmail. - The region is
AWS_REGION, orsesClient.regionin the output. - Each email goes to the recipients of its
RCPT TOcommands, blind copies included, as received.
This configuration accepts every client ("ips": ["regexp:.*"]) and does not ask for authentication. Do not
expose it beyond the network of your applications: restrict the clients, or require credentials, as below.
Where each setting goes
Section titled “Where each setting goes”| Setting | In smtp-relay |
|---|---|
| Listening port and address | port (default 10025) and bind (default localhost, 0.0.0.0 in a container) |
| SES region | AWS_REGION, or sesClient.region |
| Configuration set | sendRawEmailOptions.ConfigurationSetName |
| Source, From and Return-Path ARNs (sending authorization) | sendRawEmailOptions.SourceArn, FromArn, ReturnPathArn, see the cross-account example |
| Allowed client addresses | a whitelist filter with ips or subnets |
| SMTP username and password | a static-auth filter, or http-auth |
| TLS certificate | options.secure, options.key and options.cert, see TLS |
A restricted relay
Section titled “A restricted relay”Only clients of the private network, authenticated with the credentials of SMTP_USERNAME and SMTP_PASSWORD,
over TLS, through a configuration set:
{ "$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json", "flows": { "ses": { "filters": [ { "type": "whitelist", "subnets": ["10.0.0.0/8"] }, { "type": "static-auth" } ], "outputs": [ { "type": "aws", "ses": true, "sesClient": { "region": "eu-west-1" }, "sendRawEmailOptions": { "ConfigurationSetName": "relay" } } ] } }, "bind": "0.0.0.0", "options": { "key": "file:///etc/smtp-relay/tls.key", "cert": "file:///etc/smtp-relay/tls.crt", "authMethods": ["PLAIN", "LOGIN"] }}authOptional is not set, so clients must authenticate; they upgrade the connection with STARTTLS first. Keep
authOptional unset when you require credentials: with authOptional: true, a client the whitelist accepts
could send without authenticating (see static-auth).
Beyond SES
Section titled “Beyond SES”The same server can do more than relay to SES: store a copy of each email in S3, notify a queue, sign with DKIM through another SMTP server, or route recipients to different flows. See flows and routing.