Nethence Newdoc Olddoc Lab Your IP BBDock  

setting up outgoing emails

introduction

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

requirements

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/main.cf /etc/postfix/main.cf.dist

on an Ubuntu system, make sure those are installed,

    apt -y install postfix bsd-mailx rsyslog dnsutils nmap netcat telnet
#pmailq
    service rsyslog restart
    #container: rsyslogd
    update-rc.d rsyslog defaults
    cp -pi /etc/postfix/main.cf /etc/postfix/main.cf.dist
    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),

hostname

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/main.cf

myorigin = $mydomain

postfix reload

chroot

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/main.cf

relayhost = SMARTHOST

postfix reload

aliases

configure root mail alias to receive crontab and upgrade notifications,

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

    postmaster:     root
    root:           user@example.com
    wheeleduser:    root
    appuser:        root
    cronuser:       root

    newaliases

ready to go

watch the logs while you proceed,

    #centos,
    tail -20 /var/log/maillog &
    #ubuntu,
    tail -20 /var/log/mail.log &

now check that you receive mails from that host,

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

Home | GitHub | Donate | Contact