run postfix with smtp authentication (sasldb) in a docker container. TLS and OpenDKIM support are optional.
Forked from catatnight/postfix to add some more flexibility
- Allow to choose the certificate (default to the first cert found)
- mail.log is now displayed inside the container log
- Increase verbosity
- Allow to set the smtp restrictions
- Add a docker-compose file
- Docker 1.0
-
Build image
$ sudo docker pull catatnight/postfix
-
Create postfix container with smtp authentication
$ sudo docker run -p 25:25 \ -e MAILDOMAIN=mail.example.com -e USERS=user:pwd \ --name postfix -d catatnight/postfix # Set multiple user credentials: -e USERS=user1:pwd1 user2:pwd2 ... userN:pwdN
-
Enable OpenDKIM: save your domain key
.private
in/path/to/domainkeys
$ sudo docker run -p 25:25 \ -e MAILDOMAIN=mail.example.com -e USERS=user:pwd \ -v /path/to/domainkeys:/etc/opendkim/domainkeys \ --name postfix -d catatnight/postfix
-
Enable TLS(587): save your SSL certificates
.key
and.crt
to/path/to/certs
$ sudo docker run -p 587:587 \ -e MAILDOMAIN=mail.example.com -e USERS=user:pwd \ -v /path/to/certs:/etc/postfix/certs \ --name postfix -d catatnight/postfix
MAILDOMAIN=mail.example.com
MAILSIGNING=example.com # Will sign *@example.com instead of *@mail.example.com
USERS=user1@example.com:password1 user2@example.com:password2 ...
CERTNAME=example.com # lookup for example.com.crt and example.com.key
SMTP_RESTRICTIONS=permit_sasl_authenticated,reject_unauth_destination # SMTP restriction option (see postfix doc)
Edit to suit your needs and run docker-compose up -d --build
- Login credential should be set to (
username@mail.example.com
,password
) in Smtp Client - You can assign the port of MTA on the host machine to one other than 25 (postfix how-to)
- Read the reference below to find out how to generate domain keys and add public key to the domain's DNS records