|
How do I go about getting a users name? For example, like the names listed in the GMAIL inbox image below. |
Answered by
mjs
Aug 24, 2023
Replies: 1 comment
|
The sender name can be obtained by retrieving the Alternatively if you have the full email body (say because you fetched it as |
0 replies
Answer selected by
f0rme
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

The sender name can be obtained by retrieving the
Fromheader of an email which will give you something like eitherFirst Last <someone@email.com>or just a plain address likesomeone@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 theFromheader and the separate as above usingparseaddr.https://docs.python.org/3/library/email.examples.html