Limit Number of Recipients in To and Cc with Postfix for Authenticated Users

By | July 5, 2014

The simplest way to restrict the number of recipients in To or Cc with Postfix is the use of HEADER_CHECKS. You put in your Postfix main.cf a line like this:

header_checks = pcre:/usr/local/etc/postfix/header_checks

And you create a file /usr/local/etc/postfix/header_checks which contains this:

/^To:([^@]*@){10,}/ REJECT Sorry, your message has too many recipients.
/^Cc:([^@]*@){10,}/ REJECT Sorry, your message has too many recipients.

Restart Postfix, and any mail that contains more than 10 recipients in To or Cc will be rejected. But there seems to be no way to distinguish between authenticated users and non-authenticated users, say outgoing mail and incoming mail.

If you want to restrict Cc and To only for authenticated users you have to use a milter.

There is a  repository on GitHub with a milter to limit the number of recipients in To or Cc.

Leave a Reply

Your email address will not be published. Required fields are marked *