SPUG: Checking Email Addresses

Aryeh "Cody" Sherr asherr at cs.unm.edu
Fri Oct 6 11:05:20 CDT 2000


There is a recipe for this in the O'Reilly Reg Exp book, and recipes 16.9
and 18.9 in the Perl cookbook make a stab at it using SMTP VRFY and EXPN.  
The short answer is that you can't with 100% accuracy. However, you can
get fairly close by:

- having them type it twice to prevent typos
- checking the email for well-formedness, see
http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz 
for a monster of a regexp written by Tom Christiansen that makes a stab at
it, and asking the user to confirm if it looks like a bad address.
- do an mx lookup for that domain to see if it's valid. here's some code
blatantly taken from the cookbook:

require Net::DNS;
$domain_ok = 0;
eval {
    Net::DNS->import('mx');
    $domain_ok =1;
};

- then try to mail them something, if it fails, they'll have to try again.

that should get about 99.9% of human users.

Cody


On Thu, 5 Oct 2000, David Vergin wrote:

> Working on an on-line conferencing package...
> 
> User registers for the first time giving name and email address.
> Script reads data and sends a message with password to user's email address.
> 
> But the user unknowingly mis-types his/her email address and then waits forever
> for the password to arrive.
> 
> <Question>
> Is there a way to poll an email server to see if it recognizes a specific
> address? (And then display an error message to the user right away)
> 
> Or if the script sent the email and checked for a bounce would the bounce arrive
> back in time to present an error message to the user waiting for a confirmation
> page after hitting 'Submit'? I.e. how fast do emails to bad addresses bounce?
> [hmmm... seems like there are several ways/levels in which an email address can
> be 'bad']
> 
> Is there a solution I am not considering?
> 
> As always, url's, rtfm's, clues, suggestions of key words for searches, all
> welcome.
> 
> tia
> David
> 
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>       Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
>  For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>   Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
> 
> 
> 



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list