How to block specific Emails using Postfix

In this tutorial we’ll learn how to block/reject specific emails coming to our mail server using Postfix on Centos7.

1. First create a new file in /etc/postfix called “sender_access”

$ sudo vim /etc/postfix/sender_access

2. In this file, you can enter email addresses followed by the action you would like to perform.

[email protected] REJECT

Replace [email protected] with the Email address you want reject.

3. Don’t forget to postmap the file to prepare it for Postfix to use. Every time you modify the file, you must postmap it again or the changes won’t take affect.

$ postmap /etc/postfix/sender_access

4. Now, we need to tell Postfix to look at our new file. For this we need to edit /etc/postfix/main.cf

$ vim /etc/postfix/main.cf 

smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/sender_access

5. After doing the above changes, Restart Postfix

$ sudo systemctl restart postfix

6. Once a message comes in from one of the domains in your sender_access file, you should be able to see it being rejected in /var/log/maillog.

May 26 13:57:58 mail postfix/smtpd[15089]: NOQUEUE: reject: RCPT from mail-lf1-f49.google.com[209.85.167.49]: 554 5.7.1 <[email protected]>: Sender address rejected: Access denied; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<mail-lf1-f49.google.com>

Leave a Reply

Your email address will not be published. Required fields are marked *