How to configure postfix/dovecot setup to reject certain mail

Solution 1:

You can use header_checks and body_checks to block on certain strings. More info here. You can use smtpd_sender_restrictions to block mails from certain users. More info here.

#/etc/postfix/main.cf
header_checks = regexp:/etc/postfix/header.re
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/blacklisted_roles

#/etc/postfix/header.re
/^Subject:(.*) offensive_word /     REJECT Inappropriate word

#/etc/postfix/blacklisted_roles
[email protected]    REJECT