Postfix has features to do that called SMTPD Restriction Classes. But it's not convenient like you write some ACL with if-then-else
. For this, you can use postfwd like the answer from tomas or policyD
Here you put in main.cf
# define one restrictio class, let's name it 'specialdomain'
smtpd_restriction_classes = specialdomain
# define the restriction for this class
specialdomain =
check_sender_access hash:/etc/postfix/specialdomain2 # permit sender same domain
permit_sasl_authenticated # permint sasl_authenticated
check_sender_access hash:/etc/postfix/whitedomain # permit whitelisted domain
reject # otherwise reject
smtpd_recipient_restrictions =
check_recipient_access = hash:/etc/postfix/specialdomain
... other restriction ...
The maps
# /etc/postfix/specialdomain
example.com specialdomain
# /etc/postfix/specialdomain2
example.com OK
#/etc/postfix/whitedomain
example.net OK
example.org OK
How it works:
First postfix check if recipient listed in /etc/postfix/specialdomain
, if yes then postfix apply the restriction defined in specialdomain
parameter of main.cf
.
specialdomain
restriction has several parameters to allow email. There two check_sender_access
to check whether the sender domain was same or already whitelisted. There is also permit_sasl_authenticated
to permit the user authenticated by SASL. Otherwise reject it.