在 Python 上的 Outlook.Application 中正确过滤 Items.Restrict

问题描述 投票:0回答:1

我正在使用 pywin32 编写一个 Python 脚本,按主题从文件夹中提取 Outlook 电子邮件以在其他地方使用。

我正在使用

emails = target_folder.Items.Restrict(search_criteria)
行按主题过滤电子邮件结果。

我想根据它们是否包含特定单词来过滤它们,而不是完整的主题。

我根据其他来源尝试了以下方法。

criteria = "sample"
search_criteria = f"[Subject] = '*{criteria}*'"

但是它不起作用。当主题包含所需的字符串时,正确过滤它的正确方法是什么?

python outlook com
1个回答
0
投票

您可以使用以下过滤查询。

target_folder.Items.Restrict("@SQL=(urn:schemas:httpmail:subject LIKE '%sample%')")
© www.soinside.com 2019 - 2024. All rights reserved.