I was recently configuring my local Postfix e-mail server to relay messages destined for Gmail accounts through Google’s SMTP server. The setup is actually pretty simple, and there are numerous good articles on this subject available on the Intertubes, to name a few:
- Send Mail Postfix through Gmailâs SMTP on a Ubuntu LTS Server
- Configuring[Ubuntu] Postfix and Gmail in 10+1 Easy Steps
The above sources will give you a detailed description of what you need to do (including creating a certificate, in case you don’t have one already), I’m just going to list the essential parts here. As a prerequisite, you need a Gmail account, as Google’s SMTP server requires you to authorize before allowing you to relay anything.
Note: My e-mail server is running FreeBSD, so if you’re on a different operating system, the location of Postfix configuration files will probably be different — you might have
/etc/postfix instead of
To tell Postfix to relay all messages destined for
*@gmail.com through Google’s SMTP server, put this into
Then, create the
/usr/local/etc/postfix/sasl_passwd file, telling Postfix to authorize with your Gmail login credentials when connecting to Google’s SMTP server:
Finally, put the following into
transport_maps = hash:/usr/local/etc/postfix/transport smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/usr/local/etc/postfix/sasl_passwd smtp_sasl_mechanism_filter = plain, login smtp_sasl_security_options = noanonymous smtp_use_tls = yes
sasl_passwd files need to be hashed with
# postmap transport && postmap sasl_passwd
That’s it for the configuration. Restart Postfix to make the changes effective (again, the command below is for FreeBSD):
# /usr/local/etc/rc.d/postfix restart
That’s it — you can now test it by sending something to your Gmail account.
It’s working? Grrreat. However, you might notice that there’s one fundamental problem with this solution — any message transmitted this way has it’s original “from” address replaced with your Gmail account’s address, making it look as if it was actually sent from Gmail.
Luckily, as I found out, the “from” address will be left intact if it is listed as one of the “other addresses” assigned to your Gmail account. So, you just need to log in to your account, go to Settings → Accounts, and use the “Add another email address” option to add any addresses that you want to relay mail for.