簡體   English   中英

使用 Python 從特定日期保存 Outlook 附件

[英]Save Outlook attachment from a specific date using Python

我想知道如何將日期添加到此代碼以保存 Outlook 中的附件文件 n 電子郵件:例如,我想保存在 20/04/2020 和 01/01/2020 之間找到的文件。 你有什么想法嗎?

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'))

Outlook 對象模型提供了Items類的Find / FindNextRestrict方法來獲取與您的條件相對應的項目。

您可能還會發現如何:使用 Find 和 FindNext 方法檢索 Outlook 日歷項目文章在使用類似搜索條件的情況下很有幫助。

換線

for m in messages:

到(從我的頭頂):

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM