Configure postfix to block PHP-sent mail() to certain recipients

Dr. Gianluigi Zane Zanettini asked:

I’m trying to prevent my CentOS 6.5 server from sending out emails to a certain list of recipients. (dont_contact_me@hotmail.com, dont_contact_me@gmail.com and so on).

I’ve configured postfix like this:

/etc/postfix/main.cf:

smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recipient_access

/etc/postfix/recipient_access:

dont_contact_me@hotmail.com REJECT
dont_contact_me@gmail.com REJECT

DB is built via:

postmap hash:recipient_access

postfix is reloaded

service postfix reload

php.ini is:

sendmail_path = /usr/sbin/sendmail -t -i

Unfortunately this doesn’t seems to work. If i use PHP mail() to send a mail to dont_contact_me@hotmail.com, it is delivered as always.

What am I missing?

My answer:


You may be able to abuse smtp_generic_maps to divert this mail. Unlike the other directives you mentioned, this one operates on outgoing mail.

While it’s not capable of dropping it, it can send it to a different mailbox, where you can then take appropriate action on it (such as suspending the customer who sent the mail).

In main.cf you would have:

smtp_generic_maps = hash:/etc/postfix/generic

And in /etc/postfix/generic:

banned_address@hotmail.com abuse@example.com
dont_contact_me@live.com abuse@example.com

This should send all such mail to your abuse mailbox for you to act on.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.