Using Gmail and Postfix

08/11/2008 19:04:13
tags: mail, security

I struggled with getting postfix to send outgoing mail using Gmail for quite a bit — 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….)

Similar Pages

Comments

Very very Thanks

I have been configured successfull … Now is working how do i configure Outlook express these configuration so could you send a me through my email id:krisuresh001@gmail.com

Thanxs thanxs …………..HEEEEEEEEEEEEE

How can i add multiple users in the /etc/postfix/sasl_passwd ………please help me this is my email id : krisuresh001@gmail.com please scrape me …am waiting for your reply

I’m sure you can google sasl_passwd in order to learn more about the syntax. I am not an expert in this file, and simply learned enough to do what’s described above.

Everything is working, except “replies will go to the address of your choosing” ! How can I do that? All the emails I relay has myname@gmail.com as originating address and replies go to my gmail address.. How can I prevent that?

You have to enable your gmail account to handle other email addresses - gmail has help files for that.

Leave a comment