Restricting outgoing mail to specific domains in From Address using Postfix
Solution 1:
I can confirm that what you see in your postfix was intended behavior of reject_unlisted_sender
. This documentation page clearly states 4 conditions when postfix rejected your email
- The sender domain matches $mydestination, $inet_interfaces or $proxy_interfaces, but the sender is not listed in $local_recipient_maps, and $local_recipient_maps is not null.
- The sender domain matches $virtual_alias_domains but the sender is not listed in $virtual_alias_maps.
- The sender domain matches $virtual_mailbox_domains but the sender is not listed in $virtual_mailbox_maps, and $virtual_mailbox_maps is not null.
- The sender domain matches $relay_domains but the sender is not listed in $relay_recipient_maps, and $relay_recipient_maps is not null.
When the sender address doesn't match any condition above, by default postfix will permit it.
Back to your original question: The only way I've figured out how to do this so far is as follows. But is there anything simpler?
NO, your only options is likely SMTPD restiction classes. For other solution, you can use any policy server addon such as postfwd, policyd and others.
Solution 2:
YES I think.
Create a new Postscript regular expression access file /etc/postfix/allowed_senders
, for example:
/@microsoft.com$/ OK
/@bbc.co.uk$/ OK
/@abc.net.au$/ OK
// REJECT
Test it with e.g. postmap -q [email protected] regexp:/etc/postfix/allowed_senders
.
Use it by adding the line
smtpd_sender_restrictions = check_sender_access regexp:/etc/postfix/allowed_senders
to /etc/postfix/main.cf
.
That should do it. This is working for me, and on an old Postfix version from before the date of this question, so I don't think I'm relying on anything added since.