Postfix Configuration - Custom Mail Route
If running Postfix in a container the commands below can be used to configure a custom mail route for a domain. This will allow the Postfix server to delivery emails for the configured domain to a specific MTA/mail server instead of using the domains MX record.
- Access the container
docker exec -it <container_id> /bin/bash
- Open the transport map
nano /etc/postfix/transport
- Add the custom route using the syntax below to the transport file, save and exit
xyz.com smtp:[192.0.2.1]
- Create a hash database of the transport map
postmap /etc/postfix/transport
- Open Postfix config file
nano /etc/postfix/main.cf
- Add the transport map hash to the config
transport_maps = hash:/etc/postfix/transport
- Restart Postfix
postfix reload
If you need to add additional domains in the future, you will need to rehash the map (Step 4) and then restart Postfix (Step 7). Steps 5 and 6 will not be needed.