Reputation: 568
When using Email library, is there a way to get the internet email address without the name, so for "Jon Doe"<[email protected]>
, how can I just get [email protected]
.
I am loading a mime message from file with email.message_from_binary_file()
and then getting the FROM header by accessing the "from"
key:
message = email.message_from_binary_file()
from_header = message["from"]
I can't seem to find in Email docs how I can parse this down further to just the email address?
EDIT: Current solution that I don't think is very elegant and might be error-prone is to do a regex likes so:
from_header = re.findall('\S+@\S+', message["from"])[0][1:-1]
So get the first (and only) element from regex list and then remove the opening and closing brackets ("<"
& ">"
)
Upvotes: 0
Views: 220