471,338 Members | 1,046 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 software developers and data experts.

test if email

Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?

Thanks,

florian
Oct 12 '07 #1
15 3283
On Oct 12, 2:55 pm, Florian Lindner <Florian.Lind...@xgm.dewrote:
Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?

Thanks,

florian
What do you mean? If you're just testing the construction of the email
address string, then it's pretty easy. If you want to know if the
email address is live and works, the only way to reliably find that
out is to send a test email there to see if it goes through or
bounces.

Here's an interesting article on the topic, which is completely non-
Python related:

http://www.oreillynet.com/onlamp/blo...ail_addre.html

Mike

Oct 12 '07 #2
Florian Lindner wrote:
Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?
Nope, most any string with an @ in it could be a valid email addy. Send
a message to the addy, if it doesn't bounce, then it's valid.
Oct 12 '07 #3
On 12/10/2007, Florian Lindner <Fl*************@xgm.dewrote:
Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?
You mean a valid SMTP email address?

In reality, there isn't a way of doing this. But a good rule of thumb
is if it hasn't got at least one '@' symbol with at least one '.' to
the right of the right-most '@' symbol then it isn't valid for
internet transmission.

If you meant "test if a string is an existing email address", then
again there is no foolproof way of testing. Valid email addresses
can bounce for a variety of reasons, and invalid email addresses don't
always bounce. Using an SMTP dialogue with the server without sending
an email can have the same bounce/non-bounce (actually, accept/refuse)
results.

HTH :)
Oct 12 '07 #4
On 2007-10-12, brad <by*******@gmail.comwrote:
Florian Lindner wrote:
>Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?

Nope, most any string with an @ in it could be a valid email addy. Send
a message to the addy, if it doesn't bounce, then it's valid.
Just because it doesn't bounce, that doesn't mean it's "valid".
Some servers don't bounce e-mail to invalid addresses, they
just drop them into the bit bucket in an effort to prevent
spammers from harvesting valid e-mail addresses using
dictionary attacks.

If you send an e-mail to an address and you get a response,
then it's valid.

--
Grant Edwards grante Yow! BARRY ... That was
at the most HEART-WARMING
visi.com rendition of "I DID IT MY
WAY" I've ever heard!!
Oct 12 '07 #5
On 12/10/2007, brad <by*******@gmail.comwrote:
Florian Lindner wrote:
Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?

Nope, most any string with an @ in it could be a valid email addy. Send
a message to the addy, if it doesn't bounce, then it's valid.
Invalid email doesn't always bounce, ( or the bounces may not always reach you )

:)

--

Tim Williams
Oct 12 '07 #6
Grant Edwards wrote:
If you send an e-mail to an address and you get a response,
then it's valid.
No response could be valid too. The user may not respond. For automated
tasks, I go with the no bounce method. When things start bouncing, do
domething, but so long as they don't bounce do something else.
Oct 12 '07 #7
ky******@gmail.com wrote:
On Oct 12, 2:55 pm, Florian Lindner <Florian.Lind...@xgm.dewrote:
>Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?
here's a Perl re example... I don't know whether to laugh or cry...
don't try to replicate this in Python or you'll hurt yourself. :)

"... the only sure way to see if a supplied email address is genuine is
to send an email to it and see if the user recieves it."

http://ex-parrot.com/~pdw/Mail-RFC822-Address.html
Oct 12 '07 #8
ky******@gmail.com wrote:
On Oct 12, 2:55 pm, Florian Lindner <Florian.Lind...@xgm.dewrote:
>Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?

Thanks,

florian

What do you mean? If you're just testing the construction of the email
address string, then it's pretty easy. If you want to know if the
email address is live and works, the only way to reliably find that
out is to send a test email there to see if it goes through or
bounces.

Here's an interesting article on the topic, which is completely non-
Python related:

http://www.oreillynet.com/onlamp/blo...ail_addre.html

Answer to everybody:

I was just asking for the correct syntax of the mail address. I know about
the various problems actually impossibility to test for a live and valid
address.

Regards,

Florian
Oct 12 '07 #9
On 2007-10-12, brad <by*******@gmail.comwrote:
Grant Edwards wrote:
>If you send an e-mail to an address and you get a response,
then it's valid.

No response could be valid too.
Right. A->B doesn't mean that !A -!B

--
Grant Edwards grante Yow! Did I do an INCORRECT
at THING??
visi.com
Oct 12 '07 #10
On 2007-10-12, Florian Lindner <Fl*************@xgm.dewrote:
I was just asking for the correct syntax of the mail address. I know about
the various problems actually impossibility to test for a live and valid
address.
Don't forget to allow uucp style "bang" addresses. :)

--
Grant Edwards grante Yow! I had a lease on an
at OEDIPUS COMPLEX back in
visi.com '81 ...
Oct 12 '07 #11
On Oct 12, 4:59 pm, brad <byte8b...@gmail.comwrote:
kyoso...@gmail.com wrote:
On Oct 12, 2:55 pm, Florian Lindner <Florian.Lind...@xgm.dewrote:
Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?

here's a Perl re example... I don't know whether to laugh or cry...
don't try to replicate this in Python or you'll hurt yourself. :)

"... the only sure way to see if a supplied email address is genuine is
to send an email to it and see if the user recieves it."

http://ex-parrot.com/~pdw/Mail-RFC822-Address.html
Gotta love the comment: "somewhat pushes the limits of what it is
sensible to do with regular expressions".

Now if this is not an understatement I don't know what is!

Oct 12 '07 #12
2007/10/12, Grant Edwards <gr****@visi.com>:
On 2007-10-12, Florian Lindner <Fl*************@xgm.dewrote:
I was just asking for the correct syntax of the mail address. I know about
the various problems actually impossibility to test for a live and valid
address.

Don't forget to allow uucp style "bang" addresses. :)
no need to get there most forms won't accept the new top level domains (.name).

No need to speek of plus addressing or older messaging systems.

Heck just check for an "@" and try to deliver it. (if there's no @ you
should know wether it's a local user or not....)

hth
martin

--
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours
Oct 12 '07 #13
On 2007-10-12, George Sakkis <ge***********@gmail.comwrote:
On Oct 12, 4:59 pm, brad <byte8b...@gmail.comwrote:
>kyoso...@gmail.com wrote:
On Oct 12, 2:55 pm, Florian Lindner <Florian.Lind...@xgm.dewrote:
Hello,
is there a function in the Python stdlib to test if a string is a valid
email address?

here's a Perl re example... I don't know whether to laugh or cry...
don't try to replicate this in Python or you'll hurt yourself. :)

"... the only sure way to see if a supplied email address is genuine is
to send an email to it and see if the user recieves it."

http://ex-parrot.com/~pdw/Mail-RFC822-Address.html

Gotta love the comment: "somewhat pushes the limits of what it is
sensible to do with regular expressions".
OK, I want to know if a human generate that RE, or if it was
generated mechanically from the grammar specification. It's
hard to imagine the former, but you never know when it comes to
Perl programmers.

--
Grant Edwards grante Yow! Hmmm ... an arrogant
at bouquet with a subtle
visi.com suggestion of POLYVINYL
CHLORIDE ...
Oct 12 '07 #14
Florian Lindner <Fl*************@xgm.dewrites:
is there a function in the Python stdlib to test if a string is a
valid email address?
Not to my knowledge.

Florian Lindner <Fl*************@xgm.dewrites:
I was just asking for the correct syntax of the mail address.
Well, you weren't actually (I can't interpret your question above in
this way), but to answer this new question, read RFC 3696 §3:

RFC 3696: Application Techniques for Checking and Transformation of Names
<URL:http://www.ietf.org/rfc/rfc3696.txt>
I know about the various problems actually impossibility to test for
a live and valid address.
As you'll see from the above, the only thing you can check for
"validity" is the domain. The local-part can consist of *any*
printable ASCII characters, including "@" and any other punctuation.
Only the final delivery host gets to say whether it's valid or not.

--
\ "Saying that Java is nice because it works on all OSes is like |
`\ saying that anal sex is nice because it works on all genders" |
_o__) -- http://bash.org/ |
Ben Finney
Oct 13 '07 #15
Martin Marcher wrote:
No need to speek of plus addressing or older messaging systems.
But don't disallow a plus in the localpart. Many do.

Regards,
Björn

--
BOFH excuse #180:

ether leak

Oct 13 '07 #16

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Berthold Hoellmann | last post: by
9 posts views Thread by Berthold Höllmann | last post: by
9 posts views Thread by Hudson Reis | last post: by
176 posts views Thread by nw | last post: by
4 posts views Thread by istillshine | last post: by
2 posts views Thread by =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.