How do I blacklist email addresses via Postfix?

I have a spamassassin file:

/etc/mail/spamassassin/blacklist.cf:

blacklist_from *abcd.com.au
blacklist_from *efgh.com.au
blacklist_from *ijkl.com.au

It contains all the from addresses I wish to blacklist. It works well, except I think it would be much more efficient to have postfix discard these messages rather than accepting it and passing it to amavisd -> spamassassin and running through all the spamassassin rules, etc.

My question is, how do I do this with postfix?

I think my solution will be editing these files so:

/etc/postfix/main.cf:
body_checks = regexp:/etc/postfix/body_checks

/etc/postfix/body_checks:
SOMETHING-SOMETHING-SOMETHING


Is this the best way and if so I am having difficulty understanding how the SOMETHING-SOMETHING-SOMETHING above should be formatted?

How would I write the SOMETHING-SOMETHING-SOMETHING above to e.g. check if the From: header contains abcd.com.au?

Mac OS X (10.5.5)

Posted on Nov 11, 2010 10:17 PM

Reply
2 replies

Nov 12, 2010 1:38 PM in response to dmare

You're looking in the wrong place 🙂

As the name implies, body_checks are designed to check the body of a message and has nothing to do with the sender address.

The key you're looking for is smtpdsenderrestrictions which restricts who can send mail to your server.

First, you'll need to create a list of addresses to block, in the form:

abcd.com.au reject
efgh.com.au reject
ijkl.com.au reject


Convert this to a db using the standard postmap:

postmap /etc/postfix/sender_blacklist


(where sender_blacklist is the name of the file you added the addresses to)

then edit /etc/postfix/main.cf and add a line like:

smtpd senderrestrictions = check senderaccess hash:/etc/postfix/sender_blacklist, permit


Now, for each incoming message, postfix will check the sender against the sender_blacklist file. If it's listed with a reject keyword then the message will be rejected with no further processing.
Since this is a standard postfix access file, you can also add specific addresses (e.g. user@domain.com.au or add whitelist entries (e.g.

user@abcd.com.au OK
abcd.com.au reject


would reject all mail from the abcd.com.au domain except those from user@abcd.com.au.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do I blacklist email addresses via Postfix?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.