Postfix for outgoing emails

Introduction

You have a few choices to make

Note that DMA is like Sendmail. You absolutely need to define an FQDN somewhere. It is fine if you just tune your /etc/hosts file enough, while using a short hostname, though. Beware that you need an FQDN for your cluster names even (in case it is the same name as for the public network).

#cluster network
x.x.x.x        FQDN SHORT

#public
x.x.x.x        FQDN SHORT

Mail aliases

#netbsd/slackware
cp -i /etc/mail/aliases /etc/mail/aliases.dist
vi /etc/mail/aliases

#debian/ubuntu
cp -i /etc/aliases /etc/aliases.dist
vi /etc/aliases

root:       REAL-EMAIL-ADMIN

newaliases
#postalias /etc/mail/aliases

Standalone FQDN and listen for bounces

    #/usr/share/postfix/main.cf.debian
    mv -i /etc/postfix/main.cf /etc/postfix/main.cf.dist
    sed '/^[[:space:]]*$/d; /^[[:space:]]*#/d' /etc/postfix/main.cf.dist > /etc/postfix/main.cf

there’s nothing to change, Ubuntu/focal defaults are fine already

grep ^alias /etc/postfix/main.cf
    grep ^mydestination /etc/postfix/main.cf

Relay only and pseudo-masquerade

NO NEED TO LISTEN ON INET/INET6 (unix socket is enough)

mv -i /etc/postfix/master.cf /etc/postfix/master.cf.dist
sed '/^[[:space:]]*$/d; /^[[:space:]]*#/d' /etc/postfix/master.cf.dist > /etc/postfix/master.cf
vi /etc/postfix/master.cf

#smtp      inet  n       -       y       -       -       smtpd

can you reach your relay?

smarthost=x.x.x.x
#nmap -p 25,465,587 $smarthost
nc -vz $smarthost 25 465 587

now define it

#/usr/share/postfix/main.cf.debian
mv -i /etc/postfix/main.cf /etc/postfix/main.cf.dist
sed '/^[[:space:]]*$/d; /^[[:space:]]*#/d' /etc/postfix/main.cf.dist > /etc/postfix/main.cf
vi /etc/postfix/main.cf

myorigin = $mydomain
relayhost = x.x.x.x

grep ^alias /etc/postfix/main.cf

Operations

postfix check && echo OK || echo FAIL
systemctl restart postfix

ls -lF /etc/postfix/makedefs.out
rm -f /etc/postfix/makedefs.out

Acceptance

tail -F /var/log/maillog
tail -F /var/log/mail.log
date | mail -s `hostname` root

Resources

Postfix https://calomel.org/postfix.html

Chapter 27. Mail and news https://www.netbsd.org/docs/guide/en/chap-mail.html