Restrict or block Postfix Sender address

This article describes how to configure Postfix to restrict mails from a specific sender or domain.

Firstly edit your /etc/postfix/main.cf file, and add the following:

smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access

Next create the file /etc/postfix/sender_access, below is an example:

janedoe@acme.local  REJECT
johndoe@acme.com OK
acme.com REJECT

Now you need to create a hash file:

sudo postmap /etc/postfix/sender_access

Finally reload the postfix configuration

sudo systemctl reload postfix.service