How to route mails with Postfix based on the sender of the mail

The idea: Some big mailsystems reject mail that is not comming from the IP that correspondent with the IP of the domain's MX. But what if you want e.g. to send automatic mails from a system with another IP?
(Written 2004 by Tobias Wiersch, last changed 2004-08-18)


It's very simple if the specific server is not accepting incoming (external) mail and only serves as a mail-forwarder (relayhost):

Add to your /etc/postfix/main.cf:
sender_based_routing = yes
Add to your transport-table (normally /etc/postfix/transport):
domain.tld smtp:[]
* smtp:[]
This will send all mail from domain.tld (sender-address!) to (the square brackets disable MX/DNS lookups). All other mail will be sent via
Enabling the sender_based_routing feature of postfix will affect some other things, so I don't recommend to use this feature on a normal in/out-server (e.g. it's no longer possible to use routing via the mail's recipient and the bouncing of mails is also affected).