简体   繁体   English

python 和 imaplib:如何根据电子邮件 ID 下载附件文件

[英]python and imaplib: how to download attachment file given the id of the email

By using the search query, I am able to get the ids of the all the emails.通过使用search查询,我能够获得所有电子邮件的 ID。 Now I want to download the attachments from those email.现在我想从这些电子邮件中下载附件。 How can I implement that?我该如何实施? Any advice would be appreciated, stuck here for a day!任何建议将不胜感激,在这里停留一天!

EDIT: This is the search query:编辑:这是search查询:

m = imaplib.IMAP4_SSL('imap.gmail.com')
m.login(username, password)
m.select('inbox')
resp, data = m.uid('search', None, 'X-GM-RAW', 'has:attachment filename:xls')
emailids = data[0].split()

This has already been answered - in the body of this question:这已经得到了回答 - 在这个问题的正文中:

Get the Gmail attachment filename without downloading it 无需下载即可获取 Gmail 附件文件名

I just used it myself and it works great - although I would suggest prepending the email from the message to the filename so you have some reference point if you're doing this over lots of emails.我只是自己使用它并且效果很好 - 尽管我建议将邮件中的电子邮件添加到文件名中,这样如果您在大量电子邮件中执行此操作,您就有一些参考点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用python和imaplib4,如何下载电子邮件附件并移动到桌面上的文件夹? - Using python and imaplib4, how to download an email attachment and move into folder on desktop? Python imaplib无需下载完整附件即可下载Gmail文本 - Python imaplib download Gmail Text without downloading the full attachment Python和imaplib:获取附件名称或正文,而无需下载完整的电子邮件 - Python and imaplib: Obtain attachment names or body without downloading full email 如何使用python在imaplib中按时间对电子邮件进行排序 - How to sort email by time in imaplib using python 如何在python中使用imaplib获取电子邮件正文? - How to fetch an email body using imaplib in python? Python-从电子邮件附件下载Excel文件,然后解析 - Python - download excel file from email attachment then parse it 从Outlook下载Python附件与Imaplib4从不下载最后一个附件 - Python Download Attachment from Outlook w/ Imaplib4 Never downloads the last Attachment 如何从python中的gmail下载特定主题和日期的电子邮件附件 - how to download an email attachment from gmail in python for a particular subject and date 使用 Python 和 imaplib 在 GMail 中移动 email - Move an email in GMail with Python and imaplib Imaplib从带有附件的Gmail转发邮件(Python) - Imaplib forward mail from gmail with attachment (Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM