【发布时间】:2015-10-23 09:17:26
【问题描述】:
我正在使用Python 中的IMAPClient 库。我可以下载电子邮件中的附件。我只对 Excel 文件感兴趣。
我有兴趣从电子邮件中提取收件人列表。知道如何在Python 中做到这一点吗?
这里是可能有用的代码 sn-p
for ind_mail in emails:
msg_string = ind_mail['RFC822'].decode("utf-8")
#print(msg_string.decode("utf-8"))
email_msg = email.message_from_string(msg_string)
for part in email_msg.walk():
# Download only Excel File
filetype = part.get_content_type()
if(filetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'):
#download
【问题讨论】:
-
您的问题并不完全明确。邮件标头可以包含少量
To:、Cc:和Bcc:,它们都不能保证包含实际的收件人;如果重新发送消息,Resent-To:、Resent-Cc:等会覆盖这些消息,但需要注意的是。信封收件人列表不存储在任何地方,但许多现代邮件服务器添加了类似Delivered-To:的内容,以识别哪个本地收件人实际收到了邮件。您能否详细说明您希望提取哪些信息?
标签: python email rfc822 imapclient