使用Python根据特定主题过滤outlook电子邮件,但找不到电子邮件

问题描述 投票:0回答:1
outlook = win32com.client.Dispatch("Outlook.Application") 
mapi = outlook.GetNamespace("MAPI") 
your_address = '[email protected]' 
inbox = mapi.Folders[your_address].Folders['Inbox'].Folders['Apples']

subject_to_find = "Data List of apples" 
email_found = find_email(subject_to_find, inbox)

def find_email(subject, folder): 
    # Get all emails in the folder 
    emails = folder.Items

    # Use Restrict method to filter emails with a specific subject
    filtered_emails = emails.Restrict("[Subject] = '" + subject + "'")
    
    # Sort the filtered emails by ReceivedTime in descending order
    filtered_emails.Sort("[ReceivedTime]", True)
    
    # Get the most recent email, if any
    email = filtered_emails.GetFirst()
    
    return email

我想从电子邮件对话中获取最新的电子邮件;以下代码无法获取所述文件夹中的任何电子邮件。但如果没有限制,它可以贯穿整个电子邮件对话。不知道我做错了什么。

python outlook
1个回答
0
投票

尝试更改使用

PR_NORMALIZED_SUBJECT
属性的限制

filtered_emails = emails.Restrict("@SQL=""http://schemas.microsoft.com/mapi/proptag/0x0E1D001F"" = '" + subject + "'")

并指定不带任何前缀的值(RE/FW/等)

© www.soinside.com 2019 - 2024. All rights reserved.