[英]Save Outlook attachment from a specific date using Python
I would like to know how I could add the date to this code to save the attachment files n emails from Outlook: for example, I would like to save the files found between 20/04/2020 and 01/01/2020.我想知道如何将日期添加到此代码以保存 Outlook 中的附件文件 n 电子邮件:例如,我想保存在 20/04/2020 和 01/01/2020 之间找到的文件。 Do you have any idea, please?
你有什么想法吗?
outputDir = r"C:\Users\CMhalla\Desktop\attachment"
i=0
for m in messages:
if m.SenderEmailAddress == 'info@outlook.com':
body_content=m.Body
for attachment in m.Attachments:
i=i+1
attachment.SaveAsFile(os.path.join(outputDir,attachment.FileName + str(i)+'.xlsx'))
The Outlook object model provides the Find / FindNext and Restrict methods of the Items
class to get items that correspond to your conditions. Outlook 对象模型提供了
Items
类的Find / FindNext和Restrict方法来获取与您的条件相对应的项目。
You may also find the How To: Retrieve Outlook calendar items using Find and FindNext methods article helpful where a similar search criteria is used.您可能还会发现如何:使用 Find 和 FindNext 方法检索 Outlook 日历项目文章在使用类似搜索条件的情况下很有帮助。
Change the line换线
for m in messages:
to (off the top of my head):到(从我的头顶):
for m in messages.Restrict("([ReceivedTime] <= '04/20/2020') AND ([ReceivedTime] >= '01/01/2020') AND (SenderEmailAddress = 'info@outlook.com')"):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.