Postfix: Relay Outgoing Emails Based On Sender Address – TecAdmin

Channel: Linux
Abstract: the email was relayed through the correct SMTP server. Email log For those who need to relay outgoing emails based on the sender addresscreate a mappi

Have you ever wished you could relay outgoing emails based on the sender’s address? Well, now you can! With the help of sender_dependent_default_transport_maps, you can easily configure Postfix to route outgoing emails based on the email address of the sender. All you need to do is configure the ‘sender_dependent_default_transport_maps’ parameter in the main.cf file. This is an incredibly powerful tool that can be used to easily route emails sent from different domains through different mail servers. It can also be used to route emails from different parts of your organization to different mail servers.

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!

  1. 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
    [email protected]		smtp
    
  2. Next use the postmap command to update the Postfix lookup table for the above-created configuration file.
    sudo postmap /etc/postfix/relay_by_sender 
    
  3. Now update the Postfix main configuration file:
    sudo postconf -e "sender_dependent_default_transport_maps = hash:/etc/postfix/relay_by_sender"
    
  4. Finally, restart the Postfix service
    sudo systemctl restart postfix
    

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.

Email log

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.

Ref From: tecadmin

Related articles