Herr Bischoff


Use Postfix to Relay Email to External Server with SASL and TLS

Add this to /etc/postfix/main.cf, replacing the remote SMTP server:

relayhost = [smtp.example.com]:587
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Create /etc/postfix/sasl_passwd with the following content, replacing the remote SMTP server, username and password:

[smtp.example.com]:587 username:password

Make it accessible by root only:

chown root:root /etc/postfix/sasl_passwd
chmod 0600 /etc/postfix/sasl_passwd

Run postmap /etc/postfix/sasl_passwd to convert it into a Postfix-readable file.

Restart Postfix.

Test that it works as expected:

echo "This is a test email body!" | mail -s "This is a Subject" -a "From: you@example.com" recipient@elsewhere.com

If there is trouble, make sure to check /var/log/mail.log for hints.