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/main.cf”):

###NETWORKS PERMITTED TO RELAY MAIL###
 mynetworks = 127.0.0.0/8, 192.168.1.0/24, 172.16.0.0/16

###FOR GMAIL RELAY###
 relayhost = [smtp.gmail.com]: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.

[smtp.gmail.com]:587 USERNAME@gmail.com:PASSWORD

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 *