Centos – Postfix filter outbound mail with allow-only rules

centosfilteringpostfixsendmail

Essentially I only want to allow my CentOS box to send mail to specific addresses (with patterns if possible).

Such addresses would be:

  • user@domain.tld
  • user+*@gmail.com (in this instance I am using Gmail account with Plus Trick to serve as a recipient for a large number of fake users, however it's important that the server is not able to send to OTHER gmail users.

I've switched from Sendmail to Postfix on some friendly advice that Postfix is simply more configurable, but now I've made that switched and started digging, I'm getting just as frustrated as when I has sendmail!

I've been scouring postfix documents but there seems to be a void between where my understanding ends, and the documentation begins, and I'm failing to really gain much purchase on how to get started.

Thanks for any advice!

Best Answer

I have to wonder... Why do you want this? It sounds like you're probably expecting your mail server to do some sort of security screening that it ought not be doing. But... to answer your question...

You can probably accomplish this with the "smtpd_recipient_restrictions" option in main.cf:

smtpd_recipient_restrictions = check_recipient_access regexp:/etc/postfix/recipient_filter,
    permit_mynetworks, reject_unauth_destination

Then create a file called /etc/postfix/recipient_filter, and add your patterns:

/^user@domain.tld$/    DUNNO
/^user+.*@gmail.com$/  DUNNO
/.*/                   REJECT

The reason for DUNNO instead of OK, is so that the permit_mynetworks and reject_unauth_destination checks will still happen. With OK, presumably anyone trying to send mail (even spammers, or a virus-infested PC on your network) would be able to send email to the allowed addresses.

This configuration is untested, so may require some additional tweaking. For information on the result codes used in the /etc/postfix/recipient_filter file see read the access(5) man page here http://www.postfix.org/access.5.html.

For information on the regexp lookups supported by postfix, read here http://www.postfix.org/regexp_table.5.html.

And finally, for more information on the smtpd_recipient_restrictions option, read here http://www.postfix.org/postconf.5.html#smtpd_recipient_restrictions.

Related Topic