Nethence Newdoc Olddoc Lab Your IP BBDock  

setting up outgoing emails


making outgoing emails work can be tricky on a docker container. so here’s the full checklist that would also work for a normal system (fr:qui peut le plus peut le moins)

in brief


on a RHEL/CentOS system, make sure those are installed,

yum -y install postfix mailx rsyslog bind-utils nmap netcat telnet
cp -pi /etc/postfix/ /etc/postfix/

on an Ubuntu system, make sure those are installed,

    apt -y install postfix bsd-mailx rsyslog dnsutils nmap netcat telnet
    service rsyslog restart
    #container: rsyslogd
    update-rc.d rsyslog defaults
    cp -pi /etc/postfix/ /etc/postfix/
    postconf compatibility_level=2
service postfix start
#container: postfix start
    update-rc.d postfix defaults

public FQDN

check that your hostname is an FQDN already (either fix that on the system or change postfix myhostname),


does it resolve itself?

host `hostname`
cat /etc/hosts

note. don’t edit the hosts file on a docker container, you need to change either docker-run -h or –add-host

does that FQDN exist on the public network? If not, you need to fix myorigin (assuming the domain does exist),

vi /etc/postfix/

myorigin = $mydomain

postfix reload


if running Ubuntu, you might want to allow Postfix to resolve hosts and services from its chroot land,

cp -pf /etc/hosts /etc/services /etc/resolv.conf /var/spool/postfix/etc/
cat /var/spool/postfix/etc/{hosts,resolv.conf}

(optional) in case you got warnings about that,

mkdir -p /var/spool/postfix/lib/x86_64-linux-gnu/
cd /var/spool/postfix/lib/x86_64-linux-gnu/
cp -vl /lib/x86_64-linux-gnu/libnss_* ./
ls -alhF

using a relay

make sure it resolves,

    host SMARTHOST

or hardcode the name resolution into /etc/hosts.

check that you can reach the smtp relay,

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

finally tweak Postfix,

vi /etc/postfix/

relayhost = SMARTHOST

postfix reload


configure root mail alias to receive crontab and upgrade notifications,

    cd /etc/
    cp -pi aliases alises.dist
    vi aliases

    postmaster:     root
    wheeleduser:    root
    appuser:        root
    cronuser:       root


ready to go

watch the logs while you proceed,

    tail -20 /var/log/maillog &
    tail -20 /var/log/mail.log &

now check that you receive mails from that host,

date | mailx -s test_from_`hostname` root
#postfix flush

Home | GitHub | Donate | Contact