1

我在 python imap 库文档中找不到有关提取和检测电子邮件附件的信息。在阅读邮件标题时,我看到了关键字“附件”“类型”等。但我想知道是否有通往天堂的直接路径(电子邮件附件边界和数据提取)

4

2 回答 2

1

外部库:https ://github.com/ikvk/imap_tools

from imap_tools import MailBox

# get all attachments from INBOX and save them to files
with MailBox('imap.my.ru').login('acc', 'pwd', 'INBOX') as mailbox:
    for msg in mailbox.fetch():
        for att in msg.attachments:
            print(att.filename, att.content_type)
            with open('C:/1/{}'.format(att.filename), 'wb') as f:
                f.write(att.payload)
于 2021-02-01T04:36:50.287 回答
0

查看 email.parser 模块

http://docs.python.org/library/email.parser.html

于 2012-07-11T14:20:52.170 回答