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. (, and so on).

I’ve configured postfix like this:


smtpd_recipient_restrictions = check_recipient_access hash:/etc/postfix/recipient_access

/etc/postfix/recipient_access: REJECT 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, 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:

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.