Postfix Domain Rewriting

Posted on Wednesday May 4th, 2016

Following on from my previous postfix post, this configuration details how to rewrite the domain for addresses sent to the mail server for sending onwards.

The main entries to go in are:

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

relay_domains details all the domains that the server will accept mail for, including ones that are to be rewritten. A sample entry is as follows:    OK

and a sample entry of the canonical file:

detailing that mail to will be rewritten to

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

$ postmap relay_domains
$ postmap canonical

Restart postfix for the changes to take place.

Credit where credit is due: