【问题标题】:Python outlook sent items folder data extraction( using MAPI and pywin32)Python Outlook发送项目文件夹数据提取(使用MAPI和pywin32)
【发布时间】:2021-11-17 13:39:19
【问题描述】:

我想提取一个特定的电子邮件数据,该数据存在于 Outlook 的已发送项目文件夹中? 但我无法找到任何方法来给出这样的条件,比如如果这个特定的电子邮件出现在已发送的项目文件夹中,然后提取主题、日期和时间。

import win32com.client
from win32com.client import Dispatch

import  regex as re
from datetime import datetime, timedelta

outlook = win32com.client.Dispatch('outlook.application')
mapi = outlook.GetNamespace("MAPI")

sentitem = mapi.GetDefaultFolder(5)
messages = sentitem.Items


for msg in messages:

在我没有任何想法之后。 谁能帮我找到这个

【问题讨论】:

    标签: python python-3.x outlook pywin32


    【解决方案1】:

    您不能将正则表达式与 Outlook 对象模型一起使用,但您可以使用 Items.Find/FindNextItems.Restrict 来查找邮件。

    有关语法和示例查询,请参阅 https://docs.microsoft.com/en-us/office/vba/api/outlook.items.restrict

    【讨论】:

      【解决方案2】:

      在处理 Outlook 对象模型时,遍历所有项目并检查项目的属性并不是一个好主意:

      for msg in messages
      

      相反,OOM 提供了完成工作的三种主要方式:

      1. 使用Items 类的Find/FindNext 方法。请参阅How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET) 了解更多信息。

      2. 使用Items 类的Restrict 方法。此方法是使用Find 方法或FindNext 方法迭代集合中特定项的替代方法。如果项目数量很少,FindFindNext 方法比过滤更快。如果集合中有大量项目,则Restrict 方法的速度明显更快,尤其是在预计只能找到大型集合中的少数项目的情况下。请参阅How To: Use Restrict method to retrieve Outlook mail items from a folder 了解更多信息。

      3. Application 类的 AdvancedSearch 方法。在 Outlook 中使用 AdvancedSearch 方法的主要好处是:

        • 搜索在另一个线程中执行。您无需手动运行另一个线程,因为 AdvancedSearch 方法会在后台自动运行它。
        • 可以在任何位置(即超出某个文件夹的范围)搜索任何项目类型:邮件、约会、日历、便笺等。 RestrictFind/FindNext 方法可以应用于特定的 Items 集合(请参阅 Outlook 中 Folder 类的 Items 属性)。
        • 完全支持 DASL 查询(自定义属性也可用于搜索)。您可以在 MSDN 中的 Filtering 文章中阅读有关此内容的更多信息。为了提高搜索性能,如果为商店启用了即时搜索,则可以使用即时搜索关键字(请参阅Store 类的IsInstantSearchEnabled 属性)。
        • 您可以随时使用Search 类的Stop 方法停止搜索过程。

        Advanced search in Outlook programmatically: C#, VB.NET 文章中阅读有关AdvancedSearch 方法的更多信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-22
        • 2014-08-03
        • 1970-01-01
        • 2020-11-19
        • 1970-01-01
        相关资源
        最近更新 更多