Email Id Verification

Chris Angelico rosuav at gmail.com
Thu May 24 21:56:40 EDT 2012


On Fri, May 25, 2012 at 11:35 AM, Paul Rubin <no.email at nospam.invalid> wrote:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:
>> Why do you want to write buggy code that makes your users hate your
>> program? ...
>> The only way to validate an email address is to ACTUALLY SEND AN EMAIL TO
>> IT.
>
> Of course spamming people will make them hate you even more.  Insisting
> that people give you a valid email address (unless you have a
> demonstrably legitimate use for it) is a variant of that.

But why do you want to validate the email address? That's the
question. Usually it's because you're going to be sending emails to
that address, in which case you not only want to ensure that it's a
real address, you want to ensure that the person who keyed it in is
legitimately allowed to do so - the usual implementation of that being
"please check your emails for the confirmation code".

There are, however, ways of not-quite-sending an email. For instance,
you can connect to the domain's MX, give your HELO, MAIL FROM, and
RCPT TO commands, and then quit before sending any DATA. That won't
give a 100% guarantee, but it'll certainly tell you about a lot of
failures (most of them in that first megastep of looking up the domain
in DNS to find its MX record, and then attempting a connection).

Now, if your goal is to recognize email addresses in plain text (eg to
make them clickable), then you probably don't want true validation -
you want more of a DWIM setup where common "tails" aren't included
[for instance, an email address followed by a close bracket, like
foo at bar.com]. That's completely different.

ChrisA



More information about the Python-list mailing list