juanluisbaptiste / docker-postfix

Simple SMTP relay docker image.
GNU General Public License v3.0
336 stars 166 forks source link
docker docker-postfix postfix smtp-server

docker-postfix

Docker Build Status Docker Stars Docker Pulls

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

This image is available for the following architectures:

If you want to follow the development of this project check out my blog.

Available image tags

We use semantic versioning for this image. For all supported architectures there are the following versioned tags:

Additionally the amd64 architecture has the following tags:

NOTES:

Build instructions

Clone this repo and then:

cd docker-Postfix
sudo docker build -t juanluisbaptiste/postfix .

Or you can use the provided docker-compose files:

sudo docker-compose 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:

The following env variable(s) are optional.

To use this container from anywhere, the 25 port or the one specified by SMTP_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

To see the email logs in real time:

docker logs -f postfix

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 unless you add it as an alias.

Debugging

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