Skip to content

How to build a Docker image with sSMTP and Amazon SES

What is sSMTP?

SSMTP is a simple MTA (Mail Transfer Agent) that can be used to send email from a command line. It is not a full-fledged MTA like Postfix or Sendmail, but it is good enough for sending email notifications from your Docker containers.

What is Amazon SES (Simple Email Service)?

Amazon SES is a cloud-based email sending service that allows you to send email without having to maintain your own email servers.

Configuring sSMTP with Amazon SES

To use sSMTP with Amazon SMS, you need to configure it to use Amazon’s SMTP server.

  1. Log in to your AWS account.
  2. Sign up for the Amazon SES service.
  3. Pre-verify any email addresses you intend to use for testing on Amazon SES. You must verify both your sender and recipient email addresses, or your message will be rejected.
  4. Once you’ve confirmed the basic email service is working, request access to Amazon SES for sending emails by moving out of the sandbox.

Use the Amazon SES console to create new Amazon SES SMTP credentials. Then you have to put credentials into your sSMTP configuration file.

Let’s create a ssmtp.conf file with the following content:
AuthUser=[ Amazon SES SMTP username ]
AuthPass=[ Amaton SES SMTP password ]

Last line in ssmtp.conf config need to be keep empty! Let’s test our config in Docker.

Prepare Dockerfile

To add sSMTP to your Docker container, you can use the following Dockerfile:

FROM alpine:latest
RUN apk --update --no-cache add ssmtp mailx
COPY --chown=root:mail --chmod=0640 ssmtp.conf /etc/ssmtp/ssmtp.conf

There are only sSMTP and mailx packages inside the image. Command COPY will copy the ssmtp.conf file to the /etc/ssmtp/ssmtp.conf path. Build the image with the following command:

Terminal window
docker build . -t ssmtp

You can test the image and run it with interactive mode:

Terminal window
docker run -it --rm ssmtp

Amazon provides a mailbox simulator:

Terminal window
ssmtp -v << EMAIL
Subject: Testing email
Hi there this is a test email from sSMTP

but you can use any email address, for example, with sendmail:

Terminal window
sendmail -t << EMAIL
Subject: Test
This is a test mail.

Check your email. Congratulations! You have successfully configured sSMTP with Amazon SES in Docker.