使用 win32com python 从许多电子邮件中检索类别名称和颜色

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

我想使用

win32com
python 从许多电子邮件中检索类别名称和颜色。我对电子邮件拥有完整的管理权限。 由于某种我不明白的原因,输出提供了约翰颜色,这是我所有邮件的电子邮件。为了检索其他邮件的类别,我应该在下面的函数中更改什么?我已经在 chatGTP 上花了很多时间,但它根本没有帮助。

{'[电子邮件受保护]': {'ColorJohn': 3, '红色类别': 1, '蓝色类别': 8、“紫色类”:9、“绿色类”:5、“橙色类”:2、 '黄色类别':4},'[电子邮件受保护]':{'ColorJohn':3,'红色类别': 1、‘蓝色类’:8、‘紫色类’:9、‘绿色类’:5、 '橙色类别':2,'黄色类别':4},'[电子邮件受保护]': {'ColorJohn': 3, '红色类别': 1, '蓝色类别': 8, '紫色 类别': 9, '绿色类别': 5, '橙色类别': 2, '黄色 类别': 4}}

def get_category_colors(emails):
    outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
    category_colors_all = {}

    for user_email in emails:
        recipient = outlook.CreateRecipient(user_email)
        shared_calendar = outlook.GetSharedDefaultFolder(recipient, 9) 
        categories = shared_calendar.Session.Categories
        category_colors = {}
        for category in categories:
            category_colors[category.Name] = category.Color
        category_colors_all[user_email] = category_colors

    return category_colors_all
    
emails = ['[email protected]', '[email protected]', '[email protected]']

# Example usage
category_colors = get_category_colors(emails)
print(category_colors)

我期待这个输出:

{'[电子邮件受保护]': {'ColorJohn': 3, '红色类别': 1, '蓝色类别': 8、“紫色类”:9、“绿色类”:5、“橙色类”:2、 '黄色类别':4},'[电子邮件受保护]':{'ColorIsa':4,'红色类别': 1、‘蓝色类’:8、‘紫色类’:9、‘绿色类’:5、 '橙色类别':2,'黄色类别':4},'[电子邮件受保护]': {'ColorNora': 7, '红色类别': 1, '蓝色类别': 8, '紫色 类别': 9, '绿色类别': 5, '橙色类别': 2, '黄色 类别': 4}}

python outlook categories win32com
1个回答
0
投票

您的代码始终从主 Outlook 存储中检索类别 -

Session
属性(
Namespace
对象)是全局的,并且与从
Application.Session
检索到的对象相同。

categories = shared_calendar.Session.Categories

在 Outlook 对象模型中您对此无能为力。如果使用Redemption(我是它的作者)是一个选项,它也在商店级别上公开类别。或者,您可以访问日历中的隐藏(关联消息),该日历将类别以 XML 形式存储在其属性之一中。

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