[英]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.