简体   繁体   English

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

[英]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 / FindNextRestrict方法来获取与您的条件相对应的项目。

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.

相关问题 如何使用Python将Outlook API中的pdf附件保存到文件 - How to save pdf attachment from Outlook API to a file using python 如何使用 Python 保存来自特定发件人和日期的 MS Outlook 附件 - How to save MS Outlook attachments from specific sender and date using Python 使用Python从Outlook下载附件 - Download attachment from Outlook using Python 如何在 Python 中使用 win32com.client 保存 Outlook 中的附件? - How to save attachment from outlook using win32com.client in Python? 如何使用 Python 从 Outlook 帐户发送带有附件的邮件 - how to Send mail with attachment from your outlook account using Python 使用 python imap 从 outlook 检索附件文件(csv) - Retrieve attachment file(csv) from outlook using python imap 尝试通过 pythonCOM 从 Outlook 保存附件 - Trying to save an attachment from outlook via pythonCOM 如何使用 python 从 Outlook 中保存电子邮件 - How to save email from outlook using python 如何使用 Python 从特定文件夹和时间保存 MS Outlook 附件 - How to save MS Outlook attachments from specific folder and hour using Python 在特定日期范围内(用户输入)使用 Python 中的“exchangelib”从 Outlook 中的特定文件夹访问 email - Access email from a particular folder in Outlook, within a specific date range (user Input) using "exchangelib" in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM