Skip to content

Instantly share code, notes, and snippets.

@zyzo
Created December 30, 2014 13:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zyzo/23b2c95ffc8cb4c0152c to your computer and use it in GitHub Desktop.
Save zyzo/23b2c95ffc8cb4c0152c to your computer and use it in GitHub Desktop.
configure gmail as relay smtp using postfix
Steps to configure this server to send mail via gmail relay
1. Download postfix and required packages
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
2. Configure gmail as relay host : in /etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtpd_sasl_auth_enable = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
4. Write in /etc/postfix/master.cf
10025 inet n -n - - smtpd
3. Stock gmail username and password in /etc/postfix/sasl_passwd,
give 400 access rights + add to postmap
write :
[smtp.gmail.com]:587 username@gmail.com:password
smtp.gmail.com username@gmail.com:password
gmail-smtp.l.google.com username@gmail.com:password
to /etc/postfix/sasl_passwd
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
4. Create certificate file
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
5. Finally, reload postfix :
service postfix restart
For testing :
echo "test email from postfix | mail -s "subject" destination@xyz.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment