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:


smtpd_recipient_restrictions = check_recipient_access hash:/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?

  • It is because smtpd_*_restrictions only apply to the mails received by smtpd daemon through an SMTP transaction. The mails submitted using sendmail command is queued in maildrop queue by postdrop command, which is picked up by pickup and fed to cleanup directly.

  • You can't restrict recipients for the mails submitted through sendmail command.

The only solution to this problem is force your applications to send mail only through smtp transaction.

  • That's it, thanks! Could you please give me a guide to configure PHP to go through smtp transaction? I need a server-wide, php.ini thing because I need to handle multiple, 3rd-party application running on the server. – Dr. Gianluigi Zane Zanettini Apr 6 '14 at 9:53
  • Hope this should help stackoverflow.com/questions/112190/… – clement Apr 6 '14 at 10:25
  • That is useful but not entirely correct: you can restrict access to the mail queue with authorized_submit_users. Consult the postdrop man to know more. – Jean-Bernard Jansen Apr 15 at 16:59
  • You can use a alternative sendmail script like msmtp to transport your mail() mails over smtp.

  • After installing set sendmail_path in your php.ini file:

    sendmail_path = /usr/local/bin/msmtp -C /etc/msmtprc -t -i

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.


Ok, I worked it out as I desired using virtual_alias_maps.

I wrote about this here but basically you have to use virtual_alias_maps = hash:/path/to/myblacklist.txt and it will do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.