Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»Postfix: Relay Outgoing Emails Based On Sender Address

    Postfix: Relay Outgoing Emails Based On Sender Address

    By RahulDecember 9, 20222 Mins Read

    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.

    Advertisement

    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.

    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.

    Postfix Relayhost smtp
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

    How to Install MySQL 8.0 on RHEL & CentOS Stream 9

    How to Split Large Archives in Linux using the Command Line

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • What is the /etc/mtab File in Linux
    • The “Hello World” Challenge: Printing in 20 Different Programming Languages
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.