I found myself in need to having Postfix relay or forward an entire sub-domain to a remote server. My setup includes a number of test servers running my development installs of the Freeside Billing system.
The setups need to be able to both send and receive email. Sending is for system email delivery. Receiving is mainly for the built-in Request Tracker ticketing system. I have installed Postfix on a separate web server I am planning on replacing my primary production server.
Let’s get started…
Postfix is an extremely complex and customizable MTA. One of its many function is to provide “transport” for entire domains or individual mailboxes.
Edit: /etc/postfix/main.cf Add the following.
transport_maps = hash:/etc/postfix/transport
For each domain or sub-domain you want to relay add the following:
relay_domain = domain.com sub.domain.com sub.sub.domain.com
Edit/create /etc/postfix/transport Add the following:
domain.com smtp:127.0.0.1:10025
sub.domain.com smtp:10.20.20.20:25
sub.sub.domain.com smtp:192.168.0.101:10025
Run the following command to create a has table that Postfix can read.
$ sudo postmap /etc/postfix/transport
$ sudo systemctl restart postfix
You should be able to tail your maillog file and see mail being relayed.
Be sure to read the main page for transport.