sherlock.heroku.com

a meticulously crafted blog

Setting Up Postfix to Use Gmail as a Smtp Relay Host in Archlinux

| Comments

Setting up a MTA (mail transfer agent) to use gmail as a smtp relay host seemed to be a daunting task for me. The amount of options you can configure postfix with would fill up a book.

I came across Matthew Hawthorne’s excellent post on how to do exactly this. I will repeat his post here, modifying it slightly for archlinux.

Step 1, let’s install postfix.

1
# pacman -S postfix

Step 2, append the following to /etc/postfix/main.cf which will configure postfix for use with gmail.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# sets gmail as relay
relayhost = [smtp.gmail.com]:587

#  use tls
smtp_use_tls=yes

# use sasl when authenticating to foreign SMTP servers
smtp_sasl_auth_enable = yes 

# path to password map file
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

# list of CAs to trust when verifying server certificate
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

# eliminates default security options which are incompatible with gmail
smtp_sasl_security_options =

Step 3, create a file /etc/postfix/sasl_passwd and add your gmail credentials.

1
[smtp.gmail.com]:587  username:password

Step 4, create a postfix lookup table at /etc/postfix/sasl_passwd.db by running the following command.

1
# postmap /etc/postfix/sasl_passwd

Step 5, start the postfix daemon.

1
# rc.d start postfix

Step 6, run the following command to test.

1
$ echo 'hello world!' | mail -s 'first email' username@gmail.com

If you set up everything correctly, you should have sent out an email out to username@gmail.com.

Bonus: you can control where your local mail gets forwarded to by creating a ~/.forward file and adding your email to the file so that local mail will get sent to your email account. Check out the man page for aliases(5) for more info.

Comments