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.
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.
AnÂ open mail relayÂ is anÂ SMTPÂ server configured in such a way that it allows anyone on theÂ InternetÂ to sendÂ e-mailÂ through it, not just mail destined to or originating from known users.
To configure relaying on your Postfix mailserver, you need a valid email account in gmail (with username and password) use of SMTP-AUTH .
Gmail smtp server is ” gmail-smtp-in.l.google.com “Â .
Installed the postfix package and uncomment myhostname, my domain,myorgin andÂ inet_interfaces = all.
Set your hostname FQDN format.
Relay Setup in Postfix
To configure our Postfix server for relaying emails through Â gmail-smtp-in.l.google.com, we run
postconf -e ‘relayhost = gmail-smtp-in.l.google.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 (email@example.com) and password (XXXXXX) for Â gmail-smtp-in.l.google.comÂ must be stored inÂ /etc/postfix/sasl_passwd, therefore we do this
echo “gmail-smtp-in.l.google.comÂ Â firstname.lastname@example.org:XXXXXX” > /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 gmail-smtp-in.l.google.com(except the ones that have a local recipient.
Null message body; hope that’s ok
#tail -f /var/log/maillog
postfix/smtp: 350BD10E0049: to=<email@example.com>, relay=gmail-smtp-in.l.google.com[18.104.22.168]:25, delay=2, delays=0.07/0/0.78/1.1, dsn=2.0.0, status=sent (250 2.0.0 OK 1338992471 ve2si757562pbc.294)