jari(_dot_)aalto(_at_)ntc(_dot_)nokia(_dot_)com writes:
IMO, bad idea.
a) The address may be down or inaccessible, so you
can't get 100% assurance.
b) It takes lot of time for _each_ mail if you try to do even nslookup,
the call may block for several seconds. --> your other messages
are stuck until the domain is resolved or your mailsystem forks procmail
processes like crazy (It depends if you has "w" flag or not in a recipe)
c) It's a known fact that it's impossible to verify the existense of an
email address. (That has been discussed to boredom in news and always
the results is zero: you can't do that reliable enough)
However, if the message is destined for something like a closed mailing
list which is going to attempt to reply to the message anyway, the cost of
validating the address at the filter stage is cheaper than generating the
reply, handing it off to sendmail, sendmail does the mx lookup and fails,
generating a bounce message back to the list maintainer.
For those who want to validate the right hand side of the address, here's a
perl wrapper that encapsulates nslookup and returns an exit status
according to success of the MX lookup.
Note: you probably want to feed it the Reply-To: address, if present. I
use formail -r and extract the 'To: line it produces to determine what
address to validate.
#!/usr/local/bin/perl -w
#
# Passes the argument to nslookup, parses the result and returns 0 if the MX
# record exists, otherwise 1. Returns -1 if not called with right # of args.
#
if ($#ARGV != 0)
{
print STDERR "usage: $0 domain\n";
exit -1;
}
if ($ARGV[0] =~ /@/)
{
$domainName = substr($ARGV[0], (index($ARGV[0], "@") + 1));
}
else
{
$domainName = $ARGV[0];
}
$nslookupResult = `/usr/bin/nslookup -querytype=MX $domainName 2>&1`;
if ($nslookupResult =~ /can't find $domainName:/i)
{
exit 1;
}
exit 0;
--
-Mark <markm(_at_)XMission(_dot_)com>