Skip to content

Relaying Outgoing Emails Based on Sender Address in Postfix

Advertisement

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!

  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.

    
    info@example.com         	smtp:[ses.amazon.com]:587
    @example.net             	smtp:192.168.1.10:25
    no-relay@localhost		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
    

Verify Changes

To verify the above settings, I have sent an email from the terminal using rahul@example.net 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.

Postfix: Relay Emails Based On Sender Address
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.

Rahul

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top