Postfix filter incoming mails based on ‘mail from’ and ‘rcpt to’

postfixsmtp

I want to reject emails to my postfix server based on more than one criteria, specifically I want to block emails from Russian email addresses (or that contain Cyrillic characters, but this I suspect is harder) that are addressed to two specific recipients (but not if addressed to others).

I feel this should be straightforward especially since the 'mail from' and 'rcpt to' addresses are both supplied right at the start of the smtp negotiation. But I can't find a way to do this with postfix, and am not sure if I need some add-on package (milter?).

Best Answer

Add in a restriction class. For example:

/etc/postfix/main.cf:
smtpd_recipient_restrictions =
    check_recipient_access hash:/etc/postfix/recipient_access

smtpd_restriction_classes = no_russians
no_russians = check_sender_access pcre:/etc/postfix/no_russians


/etc/postfix/recipient_access:
recipient1@mydomain.com     no_russians
recipient2@mydomain.com     no_russians

/etc/postfix/no_russians:
/\.ru$/ REJECT
Related Question