-
|
How do I go about getting a users name? For example, like the names listed in the GMAIL inbox image below. |
Beta Was this translation helpful? Give feedback.
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 |
Beta Was this translation helpful? Give feedback.

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