使用Python IMAP获取发件人电子邮件地址 [英] Get sender email address with Python IMAP
本文介绍了使用Python IMAP获取发件人电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个python IMAP脚本,但是我的问题是,每当我想获取发件人的电子邮件地址(发件人)时,我总是得到发件人的名字以及其电子邮件地址:
I have this python IMAP script, but my problem is that, every time I want to get the sender's email address, (From), I always get the sender's first name followed by their email address:
示例:
Souleiman Benhida <souleb@gmail.com>
我如何才能提取电子邮件地址( souleb@gmail.com
)
How can i just extract the email address (souleb@gmail.com
)
我以前在PHP中这样做:
I did this before, in PHP:
$headerinfo = imap_headerinfo($connection, $count)
or die("Couldn't get header for message " . $count . " : " . imap_last_error());
$from = $headerinfo->fromaddress;
但是,在python中,我只能获得带有地址的全名,如何单独获得地址?我目前使用这个:
But, in python I can only get the full name w/address, how can I get the address alone? I currently use this:
typ, data = M.fetch(num, '(RFC822)')
mail = email.message_from_string(data[0][1])
headers = HeaderParser().parsestr(data[0][1])
message = parse_message(mail) #body
org = headers['From']
谢谢!
推荐答案
查看全文