Postfix in a container with optional SMTP authentication (sasldb), DKIM support, TLS support.
Pull from docker hub
docker pull kingsquare/postfix
Build local image from repo
docker build -t kingsquare/postfix https://github.com/kingsquare/docker-postfix.git
-
Create postfix container with smtp authentication
docker run \ -p 25:25 \ -p 587:587 \ -e maildomain=mail.example.com \ -e smtp_user=user:pwd \ --name postfix \ -d kingsquare/postfix # Set multiple user credentials: -e smtp_user=user1:pwd1,user2:pwd2,...,userN:pwdN
-
Create postfix container with smtp authentication
docker run \ -p 25:25 \ -p 587:587 \ -e maildomain=mail.example.com \ -e smtp_user=/etc/postfix/smtp_user \ --name postfix \ -d kingsquare/postfix # Set multiple user credentials: -e smtp_user=user1:pwd1,user2:pwd2,...,userN:pwdN # Set multiple user credentials from file: -v /some/file:/etc/postfix/smtp_users
-
Enable OpenDKIM: save your domain key
.private
in/path/to/domainkeys
docker run \ -p 25:25 \ -p 587:587 \ -e maildomain=mail.example.com \ -e smtp_user=user:pwd \ -e dkimselector=mail \ -v /path/to/domainkeys:/etc/opendkim/domainkeys \ --name postfix \ -d kingsquare/postfix
-
Enable OpenDKIM: override all config with custom directory
docker run \ -p 25:25 \ -p 587:587 \ -e maildomain=mail.example.com \ -e smtp_user=user:pwd \ -e dkimselector=mail \ -v /path/to/etc/opendkim:/etc/opendkim \ --name postfix \ -d kingsquare/postfix
-
Enable TLS: add your SSL certificates
.key
and.crt
files to/path/to/certs
. If you have a combined crt+key file then make sure it's extension is.crt
docker run \ -p 25:25 \ -p 587:587 \ -e maildomain=mail.example.com \ -e smtp_user=user:pwd \ -v /path/to/certs:/etc/postfix/certs \ --name postfix \ -d kingsquare/postfix
-
Optional Postfix configuration passed using environment variables:
-
inet_protocols
this allows postfix to limit the outgoing internet protocols to the given param (
ipv4
,ipv6
,all
(=default)) -
message_size_limit
To in-/decrease the message size limit, set this to the required amount in bytes (default:
10240000
= 10MB)
-
To use this i.e. -e message_size_limit=51200000
to increase the limit to 50MB
- Login credential should be set to (
[email protected]
,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