【问题标题】:Save Outlook attachment from a specific date using Python使用 Python 从特定日期保存 Outlook 附件
【发布时间】:2021-09-14 03:56:44
【问题描述】:

我想知道如何在此代码中添加日期以保存来自 Outlook 的电子邮件附件文件:例如,我想保存在 2020 年 4 月 20 日和 2020 年 1 月 1 日之间找到的文件.请问您有什么想法吗?

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

【问题讨论】:

    标签: python date email outlook email-attachments


    【解决方案1】:

    Outlook 对象模型提供Items 类的Find/FindNextRestrict 方法来获取与您的条件相对应的项目。

    在使用类似搜索条件的情况下,您可能还会发现 How To: Retrieve Outlook calendar items using Find and FindNext methods 文章很有帮助。

    【讨论】:

    • 我认为情况并非如此,因为我正在寻找从特定日期提取电子邮件:(
    • 这正是您所需要的!您只会在指定的时间范围内收到电子邮件。
    【解决方案2】:

    换行

    for m in messages:
    

    到(我的头顶):

    for m in messages.Restrict("([ReceivedTime] <= '04/20/2020') AND ([ReceivedTime] >= '01/01/2020') AND (SenderEmailAddress = 'info@outlook.com')"):
    

    【讨论】:

    • 非常感谢您!!
    猜你喜欢
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2022-01-17
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    相关资源
    最近更新 更多