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.

  1. Access the container
docker exec -it <container_id> /bin/bash
  1. Open the transport map
nano /etc/postfix/transport
  1. Add the custom route using the syntax below to the transport file, save and exit
xyz.com smtp:[192.0.2.1]
  1. Create a hash database of the transport map
postmap /etc/postfix/transport
  1. Open Postfix config file
nano /etc/postfix/main.cf
  1. Add the transport map hash to the config
transport_maps = hash:/etc/postfix/transport
  1. 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.