Python outlook发送邮件文件夹数据提取(使用MAPI和pywin32)
Python outlook sent items folder data extraction( using MAPI and pywin32)
这里我想提取一个特定的电子邮件数据,该数据存在于 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:
在我没有任何想法之后。
谁能帮我找到这个
您不能将正则表达式用于 Outlook 对象模型,但可以使用 Items.Find/FindNext
和 Items.Restrict
来查找邮件。
有关语法和示例查询,请参阅 https://docs.microsoft.com/en-us/office/vba/api/outlook.items.restrict。
在处理 Outlook 对象模型时,迭代所有项目并检查项目的属性并不是一个好主意:
for msg in messages
相反,OOM 提供了三种主要方法来完成工作:
使用Items
class的Find
/FindNext
方法。有关详细信息,请参阅 How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)。
使用Items
class的Restrict
方法。此方法是使用 Find
方法或 FindNext
方法迭代集合中特定项目的替代方法。如果项目数量较少,Find
或 FindNext
方法比过滤更快。如果集合中有大量项,Restrict
方法会明显更快,尤其是在预计仅能找到大型集合中的少数项时。有关详细信息,请参阅 How To: Use Restrict method to retrieve Outlook mail items from a folder。
AdvancedSearch
方法Application
class。在 Outlook 中使用 AdvancedSearch 方法的主要好处是:
- 搜索在另一个线程中执行。您不需要手动 运行 另一个线程,因为
AdvancedSearch
方法 运行 它会自动在后台运行。
- 可以在任何位置(即超出特定文件夹的范围)搜索任何项目类型:邮件、约会、日历、便笺等。
Restrict
和 Find
/FindNext
方法可以应用于特定的 Items
集合(参见 [=29= 的 Items
属性 ] class 在 Outlook 中)。
- 完全支持 DASL 查询(自定义属性也可用于搜索)。您可以在 MSDN 的 Filtering 文章中阅读更多相关信息。为了提高搜索性能,如果为商店启用了即时搜索,则可以使用即时搜索关键字(请参阅
Store
class 的 IsInstantSearchEnabled
属性)。
- 您可以随时使用
Search
class 的 Stop
方法停止搜索过程。
阅读 Advanced search in Outlook programmatically: C#, VB.NET 文章中有关 AdvancedSearch
方法的更多信息。
这里我想提取一个特定的电子邮件数据,该数据存在于 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:
在我没有任何想法之后。 谁能帮我找到这个
您不能将正则表达式用于 Outlook 对象模型,但可以使用 Items.Find/FindNext
和 Items.Restrict
来查找邮件。
有关语法和示例查询,请参阅 https://docs.microsoft.com/en-us/office/vba/api/outlook.items.restrict。
在处理 Outlook 对象模型时,迭代所有项目并检查项目的属性并不是一个好主意:
for msg in messages
相反,OOM 提供了三种主要方法来完成工作:
使用
Items
class的Find
/FindNext
方法。有关详细信息,请参阅 How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)。使用
Items
class的Restrict
方法。此方法是使用Find
方法或FindNext
方法迭代集合中特定项目的替代方法。如果项目数量较少,Find
或FindNext
方法比过滤更快。如果集合中有大量项,Restrict
方法会明显更快,尤其是在预计仅能找到大型集合中的少数项时。有关详细信息,请参阅 How To: Use Restrict method to retrieve Outlook mail items from a folder。AdvancedSearch
方法Application
class。在 Outlook 中使用 AdvancedSearch 方法的主要好处是:- 搜索在另一个线程中执行。您不需要手动 运行 另一个线程,因为
AdvancedSearch
方法 运行 它会自动在后台运行。 - 可以在任何位置(即超出特定文件夹的范围)搜索任何项目类型:邮件、约会、日历、便笺等。
Restrict
和Find
/FindNext
方法可以应用于特定的Items
集合(参见 [=29= 的Items
属性 ] class 在 Outlook 中)。 - 完全支持 DASL 查询(自定义属性也可用于搜索)。您可以在 MSDN 的 Filtering 文章中阅读更多相关信息。为了提高搜索性能,如果为商店启用了即时搜索,则可以使用即时搜索关键字(请参阅
Store
class 的IsInstantSearchEnabled
属性)。 - 您可以随时使用
Search
class 的Stop
方法停止搜索过程。
阅读 Advanced search in Outlook programmatically: C#, VB.NET 文章中有关
AdvancedSearch
方法的更多信息。- 搜索在另一个线程中执行。您不需要手动 运行 另一个线程,因为