Rejecting Mail to specified email addresses on OS X Server

If I have an email address that I wish to reject all email to, because for instance it has become overrun with spam, here's how…

Technorati Tags:
tutorial, mac, osx, server, email

Big thanks to jaydisc for this:

I do exactly that as follows. This requires Terminal knowledge.

Create a Postfix Access file. You can edit the existing sample located here:

/etc/postfix/access

I do this using ‘nano’ (pico‘s replacement) using ’sudo' to act as root, so:

sudo nano /etc/postfix/access

At the bottom, you can include entries like this:

bademail@mydomain.com REJECT

anotherbademail@mydomain.com REJECT

(those are tabs between the addresses and the word REJECT)

Then, you need to turn that file into a Postfix hash table with this command:

sudo postmap /etc/postfix/access

If you use virtual hosting via the editing of /etc/postfix/virtual, that command will be familiar.

Lastly, you have to tell Postfix to observe this file. I like telling Postfix to reject these messages immediately, rather than to send a bounce message. To do that, edit Postfix's main config file:

sudo nano /etc/postfix/main.cf

Near the bottom of that file (at least in mine), you will have a line like this:

smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks…

Add ‘hash:/etc/postfix/access’ to the beginning of the values of that line as such:

smtpd_recipient_restrictions = hash:/etc/postfix/access, permit_sasl_authenticated, permit_mynetworks…

Since I put it first, even authenticated users can't send to those addresses. You can order the values here as you see fit, and the first one that matches is granted. So, for example, if you put it after permit_sasl_authenticated, messages sent to these bad addresses from authenticated users would NOT be rejected at the door. I use a variance of this entire trick to only allow authenticated users to send to my junkmail address, but that's a tip for another topic.

Lastly you need to tell Postfix to reload its configuration:

sudo postfix reload

That's it!

Send a test to one of those bad addresses. Mail.app should basically tell you the message couldn't be sent and offer the standard “Use Selected Server, Try Again Later, etc.” dialog.

There is one thing I‘ll warn you of… if you have secondary mail servers, and your server is temporarily offline, and one of these badly addressed emails is held onto by the secondary server, when your primary returns, and the secondary sends, it will fail, and the secondary will be forced to deal with bouncing it, and notifying its postmaster. This won’t be an issue for most people. It is for me, but I also manage my secondaries and thus I can mirror the /etc/postfix/access file on both so they both reject those addresses at the door.

Let us know how you go.

Copyright © 2013 - Brothers Bennettw - Powered by Hexo
- Ported theme GreyShade -