Search code examples
linuxpostfix-mtamail-server

Postfix : restricting specific domain for specific user


I am new to postfix . How can I blacklist specific domain for specific user using restriction class or by some other method.

Suppose my machine has two users - user1 and user2.

I want to blacklist or block the mails from abc.com to user1@mydomain whereas [email protected] can receive.

Similarly xyz.com should be blocked for [email protected] whereas [email protected] can receive.

Thanks in advance.


Solution

  • You can use restrictions class.

    In main.cf, define your class like this:

    smtpd_restriction_classes = ... ban_abc_com

    ban_abc_com = check_sender_access hash:/etc/postfix/ban_adc_com, permit

    The ban_adc_com file will contain:

    adc.com REJECT

    Then create a file table named protected_destinations containing:

    user1@mydomain ban_abc_com

    Then link all together in main.cf:

    smtpd_recipient_restrictions = ..., check_recipient_access hash:/etc/postfix/protected_destinations

    For user2, create a new class similar to ban_adc_com, then add in protected_destinations a new line containing:

    user2@mydomain ban_xyz_com

    You can see more here: Postfix restriction classes