check_data rule set can be used to validate
recipients after all recipients have been declared with SMTP RCPT TO:
commands. Other uses for the check_data rule set
include screening a combination of sender and recipient, and
evaluating connection-based information.
The check_data rule set is called from inside
sendmail just after the SMTP DATA command is
received, but before that command is acknowledged:
RCPT TO: <email@example.com>
250 2.1.5 <firstname.lastname@example.org>... Recipient ok
354 Enter mail, end with "." on a line by itself usually acknowledged here
The workspace passed to the check_data rule set is
a count of the number of envelope recipientsthat is, the
number of accepted SMTP RCPT TO: commands. One use for this rule set
might be to reject messages that specify too many envelope
recipients. Consider the following mc
R $- $: $(math l $@ 19 $@ $1 $) # reject >=20 envelope recipients
R FALSE $# error $@ 5.7.1 $: "550 Too many recipients"
Here, we add two new sections to our mc
configuration file. The first, under LOCAL_CONFIG, defines a database
map of type arith (arith).
In the second section, following the LOCAL_RULESETS, we declare the
check_data rule set. That rule set is followed by
two rules. The first rule looks up the workspace (the LHS
$-) that contains a count of the envelope
recipients. The RHS of that rule looks up that value using the
math database map comparing the number of
recipients (the $1 in the RHS) to a literal 19. If
19 is less than that count, FALSE is returned, indicating that there
are too many recipients. Otherwise, TRUE is returned.
The second rule detects a literal FALSE (too many recipients) and
uses the $#error delivery agent (error) to reject the message.
Note that we used 19 merely as an example. Before you decide on such
a limit for your situation, you should consider how many users you
have, and how many variations on those users there are in your
aliases database. If you decide to limit the
number of recipients you will accept, be sure that limit is large
enough for all normal and mailing-list mail.