过滤在当前日期(今天的日期)发送的 outlook 电子邮件

Filter outlook emails sent on current date (today's date)

我想下载来自我的 Outlook 收件箱的特定附件。我想根据主题和发送日期过滤这些电子邮件。

这就是我正在做的事情:

 Outlook = win32com.client.Dispatch("Outlook.Application")
 olNs = Outlook.GetNamespace("MAPI")
 Inbox = olNs.GetDefaultFolder(6)

 Filter = "[Subject] = 'Important Report' And [SenderEmailAddress] = 'data@cool.com' And [SentOn] 
 > '9/26/2020 08:00 AM'"


 Items = Inbox.Items.Restrict(Filter)
 Item = Items.GetFirst()

 for attachment in Item.Attachments:
 print(attachment.FileName)
 attachment.SaveAsFile(r"C:\Users\lynnette\Desktop\file.xls")

目前,它正在使用 [SentOn] 进行过滤,但是,我使用的是特定日期。我想根据当前日期进行过滤。我已研究 Items.Restrict,但找不到当前日期过滤器。

感谢任何帮助

我相信你想做以下三项之一:

今天:

Items.Restrict("@SQL=%today(\"urn:schemas:httpmail:datereceived\")%")

从确切日期开始:

Items.Restrict("@SQL=(\"urn:schemas:httpmail:datereceived\" >= '9/26/2020 00:00')")

日期之间:

Items.Restrict("@SQL=(\"urn:schemas:httpmail:datereceived\" >= '9/26/2020 00:00' AND \"urn:schemas:httpmail:datereceived\" <= '9/27/2020 23:59')

Microsoft documentation

更新 1:

在您的代码中,您可以简单地第二次使用限制。

Items = Inbox.Items.Restrict(Filter)
Items = Items.Restrict("@SQL=%today(\"urn:schemas:httpmail:datereceived\")%")
Item = Items.GetFirst()