简体   繁体   中英

Validate Email Header in Python

I have a RegEx for validating email addresses, but I'm really looking to validate a whole From header. Any of these would be valid:

name@domain.com
<name@domain.com>
My Name <name@domain.com>

Is there anything out there that would validate these as valid from headers? I'm going to look in the smtp library :)

Be aware that there are plenty of other valid cases of e-mail addresses beyond what you've posted.

See here for a recipe that may help. Also read this for a great discussion of parsing email addresses with a regex. There are any number of good regexes in there that will match the uses you're looking for, imho :-)

I couldn't get the posted response to work, so I've been working on this and finally got this one, which seems to work so far. I'm sure it'll miss/catch something, but it's working for now.

[a-zA-Z0-9+_\-\.\ ]*[ ]*<?[a-zA-Z0-9+_\-\.]+@[0-9a-zA-Z][.-0-9a-zA-Z]*.[a-zA-Z]+>?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM