You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用win32com Python获取多邮箱分类名称与颜色的问题排查

解决Outlook共享邮箱分类颜色获取错误的问题

你在使用win32com从多个拥有管理员权限的邮箱获取分类名称及对应颜色时,所有邮箱均返回自身邮箱(john@gmx.com)的分类数据,而非目标邮箱的分类。问题出在代码中对分类集合的调用逻辑上:

原代码中shared_calendar.Session.Categories指向的是当前Outlook会话(即你自身账号)的全局分类列表,而非共享邮箱的专属分类。

修改方法

将获取分类的代码从shared_calendar.Session.Categories替换为shared_calendar.Store.Categories,因为Store对象对应共享邮箱的存储容器,其Categories属性才是该邮箱的专属分类集合。

修改后的完整函数代码

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) 
        # 关键修改:使用Store.Categories替代Session.Categories
        categories = shared_calendar.Store.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 = ['john@gmail.com', 'isa@gmail.com', 'nora@gmx.com']

# 调用示例
category_colors = get_category_colors(emails)
print(category_colors)

修改后,代码会正确读取每个共享邮箱自身的分类及对应颜色,输出将符合你的预期。

内容的提问来源于stack exchange,提问作者Mauri AZ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 09:26:12