O'Reilly logo

Perl Cookbook by Nathan Torkington, Tom Christiansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Program: expn and vrfy

This program talks directly to an SMTP server and uses the EXPN and VRFY commands to figure out whether an address is going to work. It isn’t perfect, because it relies on the remote SMTP giving meaningful information with the EXPN and VRFY commands. It uses Net::DNS if available, but can also work without.

This program inspects $0 (the program name) to see how it was called. If run as expn, it uses the EXPN command; if called as vrfy, it uses the VRFY command. Use links to install it with two names:

% cat > expn
#!/usr/bin/perl -w
...
^D
% ln expn vrfy

When you run it with an email address, the program reports what the mail server says when you try to EXPN or VRFY the address. If you have Net::DNS installed, it tries all hosts listed as mail exchangers in the DNS entry for the address.

Here’s what it looks like without Net::DNS:

% expn gnat@frii.com

               Expanding gnat at frii.com (gnat@frii.com):
            
               calisto.frii.com Hello coprolith.frii.com [207.46.130.14],
            
                   pleased to meet you
            
               <gnat@mail.frii.com>

And here’s the same address with Net::DNS installed:

% expn gnat@frii.com

               Expanding gnat at mail.frii.net (gnat@frii.com):
            
               deimos.frii.com Hello coprolith.frii.com [207.46.130.14],
            
                   pleased to meet you
            
               Nathan Torkington <gnat@deimos.frii.com>

            
               Expanding gnat at mx1.frii.net (gnat@frii.com):
            
               phobos.frii.com Hello coprolith.frii.com [207.46.130.14],
            
                   pleased to meet you
            
               <gnat@mail.frii.com>

            E
            
               xpanding gnat at mx2.frii.net (gnat@frii.com):
            
               europa.frii.com Hello coprolith.frii.com ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required