Checking if email is valid

Grant Edwards grant.b.edwards at gmail.com
Wed Nov 1 17:08:20 EDT 2023


On 2023-11-01, Simon Connah via Python-list <python-list at python.org> wrote:

> I'm building a simple project using smtplib and have a
> question. I've been doing unit testing but I'm not sure how to check
> if an email message is valid.

Send an e-mail using it?  If the right person gets the e-mail, then
it's valid?

> Using regex sounds like a bad idea to me and the other options I
> found required paying for third party services.
>
> Could someone push me in the right direction please? I just want to
> find out if a string is a valid email address.

You'll have to define "valid".  Valid syntactically according to
<what>?  Will be accepted by an SMTP server somewhere? Corresponds to
a real person?

Make sure it has an '@' in it.  Possibly require at least one '.'
after the '@'.

Trying to do anything more than that is just wasting your time and
annoying the mule.



More information about the Python-list mailing list