Open-source SMTP server
One SMTP server, any destination
Your apps speak SMTP. smtp-relay routes each email through flows and filters, then writes it to a folder, relays it through Amazon SES or another SMTP server, or stores it in S3 and Cloud Storage with an event on SQS or Pub/Sub.
docker run -p 10025:10025 \
-v "$(pwd)/emails:/smtp-relay/received_emails" \
loopingz/smtp-relay:latest configs/fake-smtp-docker.jsoncHow it works
The life of an email
From the SMTP conversation to the places the email ends up, in four steps.
The SMTP session
Your app connects and talks SMTP:
MAIL FROMnames the sender, oneRCPT TOper recipient, thenDATAsends the message. smtp-relay answers each command as it comes.MAIL FROM:<app@mydomain.com> 250 RCPT TO:<support@mydomain.com> 250 DATA 354Every flow sees every email
A configuration declares flows. They are not tried one after the other: every flow sees every connection and every email, and any number of them can take the same email.
The filter gate
Each flow's filters (IP or recipient whitelist, SMTP login, HTTP check, SPF/DKIM/DMARC) decide whether it takes the email: accepted or refused. Recipients are judged one by one, and one that no flow accepts is refused at
RCPT TO.Fan out to the outputs
Each flow that took the email runs its outputs: write it to a folder, log it, send it with Amazon SES or another SMTP server, store it in S3 or Cloud Storage, publish an event on SQS or Pub/Sub.
Routing
Pick the recipients, see where the email goes
Three flows: one for support, one for billing, one that archives everything sent to the domain. A flow takes the email if it accepted at least one of its recipients, whatever their order.
RCPT TO
support@mydomain.com: 250, taken by support and archive.
Flows and outputs
- supporttakes the email
to: support@mydomain.comSQS queue support - billingnot for this email
to: billing@mydomain.comSQS queue billing - archivetakes the email
to: regexp:.*@mydomain.comS3 bucket archive
routing.yaml
$schema: https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json
flows:
support:
filters:
- type: whitelist
to: ["support@mydomain.com"]
outputs:
- type: aws
pubsub:
topic: https://sqs.us-east-1.amazonaws.com/123456789012/support
billing:
filters:
- type: whitelist
to: ["billing@mydomain.com"]
outputs:
- type: aws
pubsub:
topic: https://sqs.us-east-1.amazonaws.com/123456789012/billing
archive:
filters:
- type: whitelist
to: ["regexp:.*@mydomain.com"]
outputs:
- type: aws
storage:
bucket: mydomain-mail-archive
path: ${iso8601}_${id}.eml
bind: 0.0.0.0
options:
authOptional: true
Typical setups
Start from a working configuration
Each one is a file of the repository's configs/ folder, also shipped in the Docker image.
Local debug inbox
Catch every email your app sends in development and write each one as a file in a folder.
{ "outputs": [ { "type": "file", "path": "./received_emails/" } ] }Relay to Amazon SES
Keep your apps on SMTP and send through the Amazon SES API, like the former aws-smtp-relay.
{ "outputs": [ { "type": "aws", "ses": true } ] }Inbound to cloud storage and events
Receive the mail of your domain, store it in a Cloud Storage bucket and publish its metadata on Pub/Sub.
{ "outputs": [ { "type": "gcp", "storage": { "bucket": "myemail", "path": "${iso8601}_${id}.eml" }, "pubsub": { "topic": "myemail" } } ] }SMTP login from the environment
Require SMTP AUTH, with the username and password read from SMTP_USERNAME and SMTP_PASSWORD.
{ "filters": [ { "type": "static-auth" } ] }
