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.

  • 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.

up vote 0 down vote accepted

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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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