Set Up Postfix For Relaying Emails Through Another Mailserver
Author: Falko Timme
This short guide shows how you can set up Postfix to relay emails through another mailserver. This can be useful if you run a Postfix mailserver in your local network and have a dynamic IP address because most dynamic IP addresses are blacklisted today. By relaying your emails through another mailserver that is hosted on a static IP address in a data center (e.g. your ISP's mailserver) you can prevent your emails from being categorized as spam.
There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!
1 Preliminary Note
To configure relaying on your Postfix mailserver, you need a valid email account (with username and password) on another mailserver (provided that this mailserver makes use of SMTP-AUTH (which it should do)). This other mailserver should be hosted on a static IP address in some data center (e.g. your ISP's mailserver).
In this guide I use smtp.example.com as the remote mailserver on which I have a valid email account with the username someuser and the password howtoforge.
I assume you have already installed Postfix as I won't go into the details of installing Postfix here.
2 Configure Postfix For Relaying
To configure our Postfix server for relaying emails through smtp.example.com, we run
postconf -e 'relayhost = smtp.example.com'
postconf -e 'smtp_sasl_auth_enable = yes'
postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
postconf -e 'smtp_sasl_security_options ='
Our username (someuser) and password (howtoforge) for smtp.example.com must be stored in /etc/postfix/sasl_passwd, therefore we do this:
echo "smtp.example.com someuser:howtoforge" > /etc/postfix/sasl_passwd
/etc/postfix/sasl_passwd must be owned by root, and noone else should have read access to that file, so we do this:
chown root:root /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
Now we must convert /etc/postfix/sasl_passwd into a format that Postfix can read:
This will create the file /etc/postfix/sasl_passwd.db.
All that is left to do is restart Postfix:
That's it. You can now test by sending emails over your mailserver and having a look at your mail log. You should see that all your emails are now passed on to smtp.example.com (except the ones that have a local recipient).
- Postfix: http://www.postfix.org