Postfix relay gmail ubuntu

Sending emails  from gmail account using PHP mail() function. Tested on Ubuntu 10.04.

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

vim /etc/postfix/main.cf:

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

Need to perform clean up after adding the line above (remove useless lines).

Add in the end of /etc/postfix/sasl_passwd:

[smtp.gmail.com]:587 YOUR_LOGIN@gmail.com:YOUR_PASSWORD

Add permissions:

sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo /etc/init.d/postfix restart

Add certificate:

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

Original article: http://maskimko.blogspot.com/2010/03/postfix-relay-smtpgmailcom.html

Useful link about testing SMTP: http://petermblair.com/email/email-service-testing/testing-smtp/


So, what do you think ?