仅获取特定日期邮件

发布于 2025-02-13 09:16:44 字数 595 浏览 0 评论 0原文

我使用以下代码获取“已发送项目”。它正在获取所有发送的邮件。我只想获取特定的日期邮件。

import win32com.client

outlook                     =   win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder                      =   outlook.Folders("[email protected]")
sent_items                  =   folder.Folders.Item("Sent Items")
sent_messages               =   sent_items.Items
for msg in sent_messages:
    received_date = msg.SentOn.strftime("%d-%m-%y")
    print(received_date)

I used following code to get 'Sent Items'. It is fetching all sent mails. I want to fetch particular date mails only.

import win32com.client

outlook                     =   win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
folder                      =   outlook.Folders("[email protected]")
sent_items                  =   folder.Folders.Item("Sent Items")
sent_messages               =   sent_items.Items
for msg in sent_messages:
    received_date = msg.SentOn.strftime("%d-%m-%y")
    print(received_date)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以可爱出名 2025-02-20 09:16:44

您可以使用查找/findnext限制 items类的方法。在这种情况下,您只能处理与您的条件相对应的项目。在以下文章中阅读有关它们的更多信息:

注意,以确保按照Microsoft Outlook期望的那样格式化日期时间比较字符串,请使用格式功能在大多数编程语言中可用(或其在编程语言中等效)。以下示例创建了一个喷气式过滤器,以查找2022年6月12日之前在当地时间3:30之前修改的所有项目。

criteria = "[LastModificationTime] < '" _ 
         & Format$("6/12/2022 3:30PM","General Date") & "'"

请参阅使用日期时间比较过滤项目以获取更多信息。

You can use the Find/FindNext or Restrict methods of the Items class for that. In that case you can deal with items that correspond to your conditions only. Read more about them in the following articles:

Note, to make sure that the date-time comparison string is formatted as Microsoft Outlook expects, use the Format function available in most programming languages (or its equivalent in your programming language). The following example creates a Jet filter to find all items that have been modified before June 12, 2022 at 3:30 PM local time.

criteria = "[LastModificationTime] < '" _ 
         & Format$("6/12/2022 3:30PM","General Date") & "'"

See Filtering Items Using a Date-time Comparison for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文