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. ([email protected], [email protected] and so on).

I’ve configured postfix like this:


smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recipient_access


[email protected] REJECT
[email protected] 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 [email protected], 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 you would have:

smtp_generic_maps = hash:/etc/postfix/generic

And in /etc/postfix/generic:

[email protected] [email protected]
[email protected] [email protected]

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

View the full question and any other answers on Server Fault.

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