Checking if email is valid

Simon Connah simon.n.connah at protonmail.com
Thu Nov 2 02:42:57 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.
> 


OK. It is going to take me some time to get round to every reply here so please bear with me.

Basically I'm writing unit tests and one of them passess in a string with an invalid email address. I need to be able to check the string to see if it is a valid email so that the unit test passess.

> 

> 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.
> 


Valid as in conforms to the standard. Although having looked at the standard that might be more difficult than originally planned.

Simon.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
URL: <https://mail.python.org/pipermail/python-list/attachments/20231102/35aa011c/attachment.sig>


More information about the Python-list mailing list