Gmail and Postfix
ComputerStuff
I struggled with getting postfix to send outgoing mail using Gmail for quite a bit this weekend. I followed various directions on the internet that seemed excessively complicated. It turns out I was right - they were needlessly complicated.
Turns out it’s pretty simple.
(I am running postfix on Mac OS 10.4.8. This is not a tutorial on getting postfix to run, but that is pretty simple as well.)
To enable relaying outgoing mail using Gmail, add the following to main.cf:
smtpd_tls_key_file =
smtp_use_tls = yes
relayhost = [smtp.gmail.com]:587
transport_maps = hash:/etc/postfix/transport
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
transport can be empty, but can be used to specify certain outgoing servers to use to relay email to certain domains.
sasl_passwd should contain:
[smtp.gmail.com]:587 username@gmail.com:password
Do the usual update commands:
sudo postmap transport
sudo postmap sasl_password
sudo postfix stop
sudo postfix start
And it should work.
By doing this, I can send outgoing mail using Gmail as my SMTP server via Mail.app, pine, and the mail command line program. Each is set to use localhost
as the SMTP server.
This avoids having to change your outgoing mail server every time you are logged into a different network, and should keep your email from getting flagged as spam if you send from a dynamically assigned IP address.
Specifically, I didn’t have to mess with OpenSSl, certificates, or anything else…
As a bonus, you can set up different email addresses with your gmail account, so that it isn’t immediately obvious you are using gmail, and replies will go to the address of your choosing. (Of course, anyone can check the headers to see that this is a gmail account, but still….)