Do you want to send out emails from different senders to different places? You can do this now! Just set up the ‘sender_dependent_default_transport_maps’ option in the main.cf file of Postfix. This lets you direct emails from specific email addresses to different mail servers. It’s a great way to handle emails from different domains or parts of your organization.
This step-by-step guide will help you configure postfix for sender based email delivery.
Step-by-Step instructions
So if you’re looking for an easy way to relay outgoing emails based on sender address, give sender_dependent_default_transport_maps a try!
- First of all, create a mapping of the sender domain or email address with the corresponding SMTP server. To do this, create a configuration file as below:
sudo nano /etc/postfix/relay_by_sender
Add the sender domain and SMTP servers one per line.
[email protected] smtp:[ses.amazon.com]:587 @example.net smtp:192.168.1.10:25 no-relay@localhost smtp
- Next use the postmap command to update the Postfix lookup table for the above-created configuration file.
sudo postmap /etc/postfix/relay_by_sender
- Now update the Postfix main configuration file:
sudo postconf -e "sender_dependent_default_transport_maps = hash:/etc/postfix/relay_by_sender"
- Finally, restart the Postfix service
sudo systemctl restart postfix
Verify Changes
To verify the above settings, I have sent an email from the terminal using [email protected]
email address. As per the above configuration, the emails from @example.net should relay through 192.168.1.10:25
SMTP server. As per the logs, the email was relayed through the correct SMTP server.
For those who need to relay outgoing emails based on the sender address, the sender_dependent_default_transport_maps parameter in Postfix can come in handy. This parameter enables you to specify which transport a message should be routed through based on its sender address.