How to create private blocklist
This will create a blocklist that will apply to sender from
for all email received by the server:
Create the rules list file:
$ sudo nano /etc/postfix/sender_access
Add to the file the desired action or actions:
username@example.com DISCARD
example.net DISCARD
Note that the DISCARD
option will recieve the mail to the server and silently delete it without delivering to any inboxes. This is generally preferable to the REJECT
option which will send a message to the sending server that the message was blocked, which the server commonly will generate a response message back to the user sending the message.
For more details and options on the sender_access
file, see access(5)
.
Create a database file:
$ sudo postmap /etc/postfix/sender_access
Edit main.cf
:
$ sudo nano /etc/postfix/main.cf
Add the check_sender_access
table to smtpd_relay_restrictions
:
smtpd_relay_restrictions=permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination,check_sender_access hash:/etc/postfix/sender_access
restart postfix
:
$ sudo service postfix restart
Emails sent to the server with username@example.com
or example.net
in the from
field will now be silently discarded.
Note to check that MiaB has not commented out the edited line after MiaB updates or when running any mailinabox
or related scripts, but system updates (e.g., unattended-upgrades
, apt
or apt-get
) should not alter the file.
While this should work generally well with MiaB, the configuration may conflict with other configurations due to the nature of how postfix
evaluates smtpd_relay_restrictions
and smtpd_recipient_restrictions
. If you experience unexpected problems after following this guide and determine they are related to this configuration, please post a new topic in the Unsupported Modifications category.