Skip to content
Discussion options

You must be logged in to vote

The sender name can be obtained by retrieving the From header of an email which will give you something like either First Last <someone@email.com> or just a plain address like someone@email.com. This can be parsed with email.utils.parseaddr to give you the separate name and address parts.

Alternatively if you have the full email body (say because you fetched it as RFC822), you can parse it with with email.parser.HeaderParser which will give you an EmailMessage object. This has a headers attribute from which you can get the From header and the separate as above using parseaddr.

https://docs.python.org/3/library/email.examples.html

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by f0rme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants