Rejecting Mail at RCPT

Ken Anderson ka at PACIFIC.NET
Thu Dec 18 16:05:40 GMT 2003

Pete wrote:

> Spicer, Kevin wrote:
>> Raymond Dijkxhoorn wrote:
>>> Hi!
>>>> Does anybody know of a way to get Sendmail to check with a remote
>>>> SMTP server to see if a user is valid at the RCPT TO:?
>>>> At my site, a good portion of the spam we get is to invalid users.
>>>> If i can get Sendmail to check with the Remote SMTP server
>>>> before it queues it, that would reduce the amount of spam on my site
>>>> by at least 30%!
>>> Put your users in LDAP and check with LDAP on your frontend servers.
>> Does anyone whether its possible to check against Active Directory (it
>> is LDAP after all)?  I tried once and failed - and never had the time
>> to pursue it.  If so, is there a howto anywhere?
> I have a great perl script that will pull all the email addresses from
> AD and make an access map for postfix - "user at   OK" is the
> access map format for postfix, should be easy enough to change to
> whatever sendmail requires? Far better than doing a query on your AD for
> every new mail that arrives, and less prone to failure of delivery
> should the AD become unavailable, even if briefly. Will email you
> tomorrow if you like - does your AD have MS Exchange info?

We use sendmail and had the same problem. I use a shell script on our
mail hub to generate a file called accessMF that contains all valid
local usernames and aliases. This works for a single domain only, so if
your mailservers receive mail for more than 1 domain, your MS boxes must
also have virtusertable that resolves address at =>
localuser at

It gets usernames out of the unix password file, and /etc/mail/aliases
and prints out the accessMF file. accessMF get's scp'd over to our MS
machines as /etc/mail/access. YMMV, as this script isn't very careful
about what it does, and it has not been tested on any other systems.
(also, watch the line wraps!)

--- snip ----

cd /etc/mail/
cat /etc/passwd | \
awk -F : '{print "To:"$1"\tRELAY"}' >> accessMF
for i in `cat aliases | /bin/grep -v "^#" \
|awk -F : '{print $1}'`; do \
x=`/bin/grep "^$i:" /etc/passwd`; \
if($x) then \
echo "TO:$i at     RELAY" >> accessMF ; \
fi; \
echo "    ERROR:5.1.1:550 User unknown" >> accessMF;

--- snip ----

See for more info.

Ken A.

More information about the MailScanner mailing list