Postfix Domain Relaying

Posted on Wednesday May 4th, 2016

Work has two external valid IPs with seperate mail servers listening. Today I needed to configure one of the mail servers to forward mail to the other (main) server while rejecting anything not for our domain.

The main entries to go in main.cf are:

# The domains that the server will accept mail for
relay_domains = $myhostname, hash:/etc/postfix/relay_domains
# The transport mapping for each domain
transport_maps = hash:/etc/postfix/transport

A sample entry for relay_domains is as follows, detailing the domains that we want to act as a relay for:

example1.com    OK
example2.com    OK

and a sample entry of the transport file:

example1.com    smtp:server.domain1.com
example2.com    smtp:server.domain2.com

As usual, the two files need to be converted to their db counterparts:

$ postmap relay_domains
$ postmap transport

Restart postfix for the changes to take place.

Credit where credit is due: http://www.binarytides.com/postfix-mail-forwarding-debian/