gpt4 book ai didi

outlook - 以编程方式设置 Outlook 邮件项目的类别?

转载 作者:行者123 更新时间:2023-12-04 00:36:18 27 4
gpt4 key购买 nike

似乎没有太多信息或任何好的代码示例用于以编程方式设置 Outlook 2007 MailItem 的类别。

MSDN has a limited page ,并提到使用 VB 的 拆分 功能,或多或少说“从这里开始你要靠自己了,所以自己解决吧”。

据我所知,我们将类别作为邮件项的逗号分隔字符串属性进行操作。这似乎有点原始,仅此而已吗?

每个人都只是挖掘他们的字符串函数库并解析 Categories 属性,相信当为单个邮件项目设置多个类别并且(天堂禁止)类别被重命名时不会陷入困惑吗?

最佳答案

您可以选择以任何您选择的方式操作以逗号分隔的类别字符串。要插入一个类别,我通常会检查当前字符串是否为空,然后再分配它。如果类别不为空,那么如果它不存在,我会附加它。要删除项目,我只需将类别名称替换为空字符串。

添加类别

 var customCat = "Custom Category";
if (mailItem.Categories == null) // no current categories assigned
mailItem.Categories = customCat;
else if (!mailItem.Categories.Contains(customCat)) // insert as first assigned category
mailItem.Categories = string.Format("{0}, {1}", customCat, mailItem.Categories);

删除类别

var customCat = "Custom Category";
if (mailItem.Categories.Contains(customCat))
mailItem.Categories = mailItem.Categories.Replace(string.Format("{0}, ", customCat), "").Replace(string.Format("{0}", customCat), "");

操作字符串的方法有很多种——它们只是选择在底层保持简单的序列化数据结构。

我倾向于在加载项启动期间创建自己的类别以验证它们是否存在。当然 - 类别重命名是一个问题,但是如果您确保每次加载加载项时您的类别都存在,您至少可以确保一定程度的有效性。

要管理 Outlook 类别,您可以使用 ThisAddIn.Application.Session.Categories .

var customCat = "Custom Category";
if (Application.Session.Categories[customCat] == null)
Application.Session.Categories.Add(customCat, Outlook.OlCategoryColor.olCategoryColorDarkRed);

关于outlook - 以编程方式设置 Outlook 邮件项目的类别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9162449/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com