Nethence NEWDOC OLDDOC Lab Webmail Your IP BBDock  

Setting up outgoing emails on docker containers

Tune your env,

export DEBIAN_FRONTEND=noninteractive
export TERM=xterm
alias runq='postfix flush'
alias netstata='netstat -antpe --inet --inet6'

apt -y install \
    postfix pmailq bsd-mailx rsyslog

Check that the docker host or the container can reach the smtp relay,

nmap -p 25,465,587 SMTP_SMARTHOST
nc -v -z SMTP_SMARTHOST 25 465 587

Eventually hardcode the name resolution of the smarthost into /etc/hosts.

Setup the mail aliases,

cd /etc/
cp -pi aliases alises.dist
cat >> aliases <<-EOF
root: user@example.com
appuser: root
#wheeleduser: root
EOF
newaliases

The MTA was already installed above, you just need to configure it now,

cd /etc/postfix/
mv -i main.cf main.cf.dist
sed '/^relayhost =/d' main.cf.dist > main.cf
cat >> main.cf <<-EOF
relayhost = SMTP_SMARTHOST
EOF
tail main.cf

ps aux | grep rsyslog
service rsyslog start
update-rc.d rsyslog defaults

ps aux | grep postfix
ps aux | grep master
postconf compatibility_level=2
service postfix start
update-rc.d postfix defaults

check,

date | mailx -s test_from_`hostname` root
mailq
tail /var/log/mail.log

Note. Change SMTP_SMARTHOST accordingly.