Converting multiple lines of email to a dictionary (multiple E-Mail with a name in one line).
emailstring = 'Friends < friend@email.com >, John Smith < john.smith@email.com >,"Smith" < jane.smith@uconn.edu >'
Separate a line with a comma
email_list = emailstring.split(',')
the name is the key, and the email is the meaning and makes the dictionary.
email_dict = dict(map(lambda x: email.utils.parseaddr(x), email_list))
Result:
{'John Smith': ' john.smith@email.com ', 'Friends': ' friend@email.com ', 'Smith': ' jane.smith@uconn.edu '}
Note:
If there is the same name with a different email identifier, then one entry is skipped.
'Friends < friend@email.com >, John Smith < john.smith@email.com >,"Smith" < jane.smith@uconn.edu >, Friends < friend_co@email.com >'
Friends are duplicated 2 times.
source share