Erik Rigtorp

Configure Postfix to use external SMTP server as relay

This is a short guide how to setup Postfix to deliver mail using an external SMTP server as relay host.

Install postfix:

dnf install postfix

Configure postfix:

postconf inet_interfaces=localhost
postconf relayhost="[smtp.gmail.com]:587"
postconf smtp_use_tls=yes
postconf smtp_sasl_auth_enable=yes
postconf smtp_sasl_security_options=
postconf smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd

Setup credentials:

echo "[smtp.gmail.com]:587 user@gmail.com:password" > /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd

Forward root mail:

sed -i 's/^#*root:.*/root: user@gmail.com/' /etc/aliases
newaliases

Enable and restart postfix:

systemctl enable postfix
systemctl restart postfix