FW: [Tutor] Checking for valid e-mails

Branimir Petrovic BranimirP@cpas.com
Thu Jan 30 17:43:00 2003


> -----Original Message-----
> From: Charlie Clark [mailto:charlie@begeistert.org]
> Sent: January 30, 2003 11:39 AM
> To: tutor@python.org
> Subject: [Tutor] Checking for valid e-mails
> 
> 
> Dear list,
> 
> I have a bundle of e-mail addresses to check for validity and 
> have come 
> across a Python class which does this but not well enuff. I 
> have found some 
> perl code which is better but I'm having trouble translating 
> some of the 
> perl expressions.


You have to keep on mind that: 

- E-mail validation is NOT a trivial matter (see RFC2822 for 
full set of rules to see what you are up against),

Proper validation would respect all pattern rules imposed by 
governing RFC, and would also check and validate the domain
part (against the list of valid and registered domains).

- Even if valid pattern wise - and if target domain exists,
and if mail host for the domain is 'there' and responds, there
is absolutely no guarantee that that particular user/mailbox 
exists as well, and that's what effectively kills the purpose
of doing it too seriously.

Because it is so hard to do it properly, and ultimately futile
on the account of the above point, solutions you can find
'out there' are in the range of either completely broken to
'almost working'...

If you are in mood for a chuckle, see the 'pure' regexp
solution (compliant with now obsolete RFC822):

http://www.foad.org/~abigail/Perl/url3.regex

If 'almost there' (good enough) is what would please you,
you can have a look at this JScript:

http://www.interclasse.com/scripts/EMailValidatorCLS.php

that I've done some time ago, before 'seeing the light' 
(discovering Python). The same thing can be done in Python
better and closer to the specs, but I do not think that
effort in this direction is worthwhile after all.

Branimir