Simple SMTP relay docker image.
Find a file
turboaaa e7eb0a9d8e
Add header tag creation.
This will create a tag in email headers that can be used for filtering by receiving servers. I use this image for relaying through exchange online, and the nature of how I run my containers prevents me from setting static IPs as a filter. With a tag for exchange to look at, I can make sure emails from the relay are not hitting the junk folder.

Without setting the HEADER_TAG variable, the script will create a randomly generated tag and move on. It is not a requirement to make use of this feature.
2019-01-16 12:34:48 -05:00
etc Remove extra verbose parameters from postfix command. 2018-05-09 02:05:50 -05:00
docker-compose.dev.yml Added docker-compose files. 2018-03-06 01:24:32 -05:00
docker-compose.yml Added docker-compose files. 2018-03-06 01:24:32 -05:00
Dockerfile Clean up yum cahches. 2018-05-24 12:32:10 +09:00
README.md Make the smtp server port configurable. 2018-05-24 12:14:45 +09:00
run.sh Add header tag creation. 2019-01-16 12:34:48 -05:00

docker-postfix

Docker Stars Docker Pulls

Simple Postfix SMTP TLS relay docker image with no local authentication enabled (to be run in a secure LAN).

It also includes rsyslog to enable logging to stdout.

Build instructions

Clone this repo and then:

cd docker-Postfix
sudo docker build -t postfix .

Or you can use the provided docker-compose files:

sudo docker-compose -f docker-compose.yml -f docker-compose.dev.yml build

For more information on using multiple compose files see here. You can also find a prebuilt docker image from Docker Hub, which can be pulled with this command:

sudo docker pull juanluisbaptiste/postfix:latest

How to run it

The following env variables need to be passed to the container:

  • SMTP_SERVER Server address of the SMTP server to use.
  • SMTP_PORT (Optional, Default value: 587) Port address of the SMTP server to use.
  • SMTP_USERNAME Username to authenticate with.
  • SMTP_PASSWORD Password of the SMTP user.
  • SERVER_HOSTNAME Server hostname for the Postfix container. Emails will appear to come from the hostname's domain.

To use this container from anywhere, the 25 port needs to be exposed to the docker host server:

docker run -d --name postfix -p "25:25"  \ 
       -e SMTP_SERVER=smtp.bar.com \
       -e SMTP_USERNAME=foo@bar.com \
       -e SMTP_PASSWORD=XXXXXXXX \
       -e SERVER_HOSTNAME=helpdesk.mycompany.com \
       juanluisbaptiste/postfix

If you are going to use this container from other docker containers then it's better to just publish the port:

docker run -d --name postfix -P \
       -e SMTP_SERVER=smtp.bar.com \
       -e SMTP_USERNAME=foo@bar.com \
       -e SMTP_PASSWORD=XXXXXXXX \
       -e SERVER_HOSTNAME=helpdesk.mycompany.com \           
       juanluisbaptiste/postfix

Or if you can start the service using the provided docker-compose file for production use:

sudo docker-compose up -d

A note about using gmail as a relay

Gmail by default does not allow email clients that don't use OAUTH 2 for authentication (like Thunderbird or Outlook). First you need to enable access to "Less secure apps" on your google settings.

Also take into account that email From: header will contain the email address of the account being used to authenticate against the Gmail SMTP server(SMTP_USERNAME), the one on the email will be ignored by Gmail.

Debugging

If you need troubleshooting the container you can set the environment variable DEBUG=yes for a more verbose output.