Postfix GMail SMTP Relay

Follow these steps to create a Postfix SMTP relay that sends external mail via a GMail account. The GMail config comes from Rahul at rtcamp.

First off install the required packages:

sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules

Add the following to your Postfix config file (normally located at “etc/postfix/”):

 mynetworks =,,

 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

Edit /etc/postfix/sasl_passwd and add your GMail account details, I would advise you create a GMail account specifically for mail relay.


Set permissions on the newly created config files:

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

Validate certificates and restart postfix:

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

Finished! You can now relay mail to any external address.


Leave a Reply

Your email address will not be published. Required fields are marked *