Using Gmail as Postfix relay in Ubuntu

Here’s are consolidated set of instructions for setting up a postfix gmail smarthost on Ubuntu 10.10. 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).

  1. Install Postfix
  2. sudo apt-get install postfix
    
  3. 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
  4. 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.
  5. 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
    
  6. And create the /etc/postfix/sasl_passwd with one line (replace the user and password with your own)
  7. smtp.gmail.com some.user@gmail.com:PASSWORD
    
  8. Rebuild the hash:
  9. postmap /etc/postfix/sasl_passwd
    
  10. Restart postfix:
  11. /etc/init.d/postfix restart
    
  12. You can optionally lock down your password file
  13. 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.

via braiden.org, techienote.com