Using GMail as a relay with Postfix
TweetFri 22 July 2011
I fiddled a bit with this, so I thought I'd do a no-nonsense guide to doing this. There are other guides, but a lot of them are incomplete and will leave you with queueing issues or annoyances.
The science bit:
smtp_use_tls = 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
# Send all mail through smtp.gmail.com
relayhost = smtp.gmail.com
# Stop getting a catpcha, hopefully.
smtp_destination_rate_delay = 60
relay_destination_rate_delay = 60
Then, edit /etc/postfix/sasl_passwd:
smtp.gmail.com myemail@gmail.com:MyPaSsWoRd
It doesn't have to be an @gmail account, it can be a GAFYD account, once you've logged into it once to activate it.
Then just generate the map file for the sasl_passwd file and reload. As root:
postmap sasl_passwd
postfix reload
And you're done. Monitor your queue a few times over the first few days to make sure stupid stuff hasn't happened (the delay between mails might get tweaked), but in general this has worked for me.
Have fun.