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).

  1. Install postfix.
    sudo apt-get install postfix
  2. The deb-installer will prompt you to answer a series of questions
    1. Type of mail server : Satellite System
    2. Mail Name : example.org (the name you want on your outbound mail)
    3. SMTP relay host : smtp.gmail.com
    4. Postmaster : I left this blank
    5. Other destinations : I left this blank
    6. Synchronous Queues : your choice, won’t impact the relaying
    7. Network blocks to allow relay : default (unless you know what your doing)
    8. Mailbox size : your choice, won’t impact relaying
    9. Local address : i left this as ‘+’
    10. Listen Address : all, your choice
  3. 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
  4. 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
  5. Rebuild the hash:
    postmap /etc/postfix/sasl_passwd
  6. Restart postfix:
    /etc/init.d/postfix/restart
  7. 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.

Tags: ,

3 Responses to “Using gmail as a Postfix Smarthost”

  1. Alroger Filho Says:

    Thank you for the simple and effective guide. My Ubuntu 9.10 now sends mails through my GMail Apps account.

  2. K. Hendrik Says:

    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

  3. braiden Says:

    @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