Parsing “From” addresses from email text

前端 未结 8 2094
春和景丽
春和景丽 2021-02-19 03:56

I\'m trying to extract email addresses from plain text transcripts of emails. I\'ve cobbled together a bit of code to find the addresses themselves, but I don\'t know how to mak

8条回答
  •  被撕碎了的回忆
    2021-02-19 04:41

    import email
    msg = email.message_from_string(str)
    
    # or
    # f = open(file)
    # msg = email.message_from_file(f)
    
    msg['from']
    
    # and optionally
    from email.utils import parseaddr
    addr = parseaddr(msg['from'])
    

提交回复
热议问题