Postfix sender_dependent_default_transport_maps per domain outgoing IP

Postfix allows to route mails through specific IPs depending on a senders domain or email address.
This is achieved through sender_dependent_default_transport_map.
Suppose we have 3 domains and we want to assign independent outgoing IP address for each of them.
Lets create 3 different transport for them in master.cf

smtp1  unix -       -       n       -       -       smtp
-o smtp_bind_address=11.11.11.11
-o smtp_helo_name=fqdn.domain1.com
-o syslog_name=postfix-domain1

smtp2  unix -       -       n       -       -       smtp
-o smtp_bind_address=22.22.22.22
-o smtp_helo_name=fqdn.domain2.co.in
-o syslog_name=postfix-domain2

smtp3  unix -       -       n       -       -       smtp
-o smtp_bind_address=33.33.33.33
-o smtp_helo_name=fqdn.domain3.org
-o syslog_name=postfix-domain3

Next we create sender transport mapping in a new file /etc/postfix/sender_map. This file contain a regular expression matching the domain with a smtp transport to use.

/@domain1\.com/              smtp1:
/@domain2\.co\.in/           smtp2:
/@domain3\.org/              smtp3:

Finally in main.cf we make use of sender_dependent_default_transport_map to declare the file to use for mapping.

sender_dependent_default_transport_map = /etc/postfix/sender_map

reload Postfix and send a test mail through the server. Check headers and see the mails for the domains coming from their designated IPs.

This can be further extended for per email sender IP if required, just define a proper regex mapping the email address to the transport like below

/user\.name@domain1\.com/              smtp2:
/myname@domain3\.org/                  smtp4:

How useful was this post?

Click on a star to rate it!

Average rating 4.1 / 5. Vote count: 16

No votes so far! Be the first to rate this post.

Leave a comment

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