Creating a Mail gateway

Many of us have plenty of servers and services that need to send email, more than likely you are either sending it from your network or using gmail’s free service. This can result in you getting blacklisted or even internet cut, if you send from your home result. Using Gmail has drawbacks too, for example you have to keep a app password around which prevents 2fa from working properly.

The solution is Amazon’s Simple Email Service (SES). It only costs 10 cents for 1,000 emails so you only spend 10cents a month. They also make it easy to add dkim, dmarc, etc which you want to prevent going to spam. If you do choose to use another service these steps should translate over.

NOTE You may need to request to get out sandbox if you want to send to emails outside of your domain or have multiple recieving addresses: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html. Just request a low(ish) amount. And for the use say you will use it for notification emails. (of course don’t lie here as it could get you banned)

After Requesting production access, you will need to create a SMTP user. To do that login to the aws console. In the search box on top type in Simple Email Service. Click SMTP settings on the left side:

Click “Create My SMTP Credentials”

In the username you can either leave it or put something descriptive like “mail_relay_user”. After clicking create make sure to write down or download the credentials as you won’t be able to access it afterwords. Once you have created your user put the following in your docker-compose, replace mailname, relay_domains, Relay networks( Networks you’re sending emails from to docker), Ses user and password.

mail-relay:
image: ixdotai/smtp:v0.0.5
container_name: mail_relay
environment:
  - SES_USER=<ses_user>
  - MAILNAME=hostname.example.com
  - RELAY_DOMAINS=example.com
  - RELAY_NETWORKS=:192.168.1.0/24:127.0.0.1/8
  - SES_PASSWORD=<ses_Password>
  - SES_REGION=us-west-2
  - SES_PORT=25
  - PORT=5555
ports:
  - 5555:5555
restart: unless-stopped

Now you can setup your other servers/services to use this mail relay.

Just do

SMTP HOST: DOCKER_HOST_IP:5555

or your equivalent setting

For servers you want to install postfix on your system and set it up as a satellite system use your hostname as the mail system name and for the relay name, you will use the docker_host:5555. If postfix is already set up, you will set relayhost=docker_host:5555