Nov 10, 2018

How to Relay Postfix mails

You can relay your postfix emails to send through Gmail or sendgrid etc.

For example for Gmail, edit your /etc/postfix/

relayhost = []:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

Specified your Gmail username and password in a different file /etc/postfix/sasl_passwd


Fix permission and update postfix config to use sasl_passwd file:

sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

validate certificates:

cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem

reload postfix config:

sudo /etc/init.d/postfix reload
test it:

echo "Test mail" | mail -s "Test email"