Using gmail as a Postfix Smarthost
Here’s are consolidated set of instructions for setting up a postfix gmail smarthost on Ubuntu 8.04. In “smarthost” configuration, the local mail transport agent (MTA) routes all mail to another server for delivery. This is useful since frequently you won’t want to try to deliver mail yourself (SPF and/or blacklisting would likely squash your message as spam).
- Install postfix.
sudo apt-get install postfix
- The deb-installer will prompt you to answer a series of questions
- Type of mail server : Satellite System
- Mail Name : example.org (the name you want on your outbound mail)
- SMTP relay host : smtp.gmail.com
- Postmaster : I left this blank
- Other destinations : I left this blank
- Synchronous Queues : your choice, won’t impact the relaying
- Network blocks to allow relay : default (unless you know what your doing)
- Mailbox size : your choice, won’t impact relaying
- Local address : i left this as ‘+’
- Listen Address : all, your choice
- We’re almost done, but need some tweaks in postfix config /etc/postfix/main.cf. Add the following lines to enable TLS and passwords on outbound connections.
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
- And create the /etc/postfix/sasl_passwd with one line (replace the user and password with your own)
smtp.gmail.com some.user@gmail.com:PASSWORD
- Rebuild the hash:
postmap /etc/postfix/sasl_passwd
- Restart postfix:
/etc/init.d/postfix/restart
- You can optionally lock down your password file
chmod 640 /etc/postfix/sasl_passwd* chown postfix.postfix /etc/postfix/sasl_passwd*
Thats all there is to it. Here’s my main.cf for reference.

January 15th, 2010 at 3:42 pm
Thank you for the simple and effective guide. My Ubuntu 9.10 now sends mails through my GMail Apps account.
September 17th, 2010 at 1:23 pm
Hi,
thank you very much for the guide. I’ve got 3 more questions:
1. wouldn’t it be better to chmod the the passwd file to 600
2. I want emails send to locale users like root to be redirected to my e-mail adress is that possible?
3. If i want my gmail address to be used as the Mail name how would i do that?
Thanks again
best
K. Hendrik
September 18th, 2010 at 8:43 pm
@K. Hendrik,
I’ll try to answer your questions:
1. Your right 600 is probably safest. Just need to make sure the user under which postfix runs can read the file.
2. Yes, just update ‘/etc/aliases’, with something like ‘root: my.address@gmail.com‘. Make sure to run ‘postalias /etc/aliases’ after you edit the file.
3. Gmail will re-write the From and return path to that of your gmail account when it sends mail.
Braiden