There's a way (although not quite clean in my opinion), matching it with the header_checks
parameter. For example:
header_checks = pcre:/etc/postfix/my_relays
Now in /etc/postfix/my_relays
:
/^From:.*asender\@domain1\.com/ smtp1:[host1.example.com]
/^From:.*anothersender\@domain2\.com/ smtp2:[host2.example.com]
The smtp1
and smtp2
actions are only needed if you need to authenticate on the host1.example.com
or host2.example.com
servers by password, otherwise replacing them with the smtp
keyword would be enough.
If you need to authenticate against those servers, you need to define what is smtp1
and smtp2
in your master.cf
file:
smtp1 unix - - - - 10 smtp
-o smtp_sasl_password_maps=hash:/etc/postfix/smtp1.relay
smtp2 unix - - - - 10 smtp
-o smtp_sasl_password_maps=hash:/etc/postfix/smtp2.relay
As a last step, your smtp[12].relay
files have to include the authentication parameters to connect to those hosts (I remark this is only needed if you need authentication).
[hostX.example.com] userX:passwordX
This command is perfect to filter mail senders, but I want to filter both senders and receivers at the same time. With a certain incoming mail and outgoing mail, filter using an external relay. – Contertulio – 2017-01-20T08:32:54.777