using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
namespace OutlookAddIn20
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application objApplication = Globals.ThisAddIn.Application;
Outlook.NameSpace objSession = objApplication.Session;
Outlook.Categories objCategories = objSession.Categories;
try
{
Outlook.MailItem objMailItem = objApplication.ActiveExplorer().Selection[1] as Outlook.MailItem;
if (objMailItem != null)
{
if (objMailItem.Categories != null)
{
string[] strCategories = objMailItem.Categories.Split(',');
foreach (string strCategory in strCategories)
{
Outlook.Category objCategory = objCategories[strCategory.Trim()]; //这一步非常重要,在有多个分类的情况下每个分类间有“, ”隔开。在使用时必须先去掉前导空格。
MessageBox.Show(objCategory.Color.ToString());
}
}
else
{
MessageBox.Show("There no flag");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message+"\n"+ex.StackTrace);
}
}
}
}实现环境:Visual Studio 2010, Outlook 2010, .Net Framework 4.0, VSTO runtime 4.0

本文介绍了一个使用C#编写的Outlook插件,该插件能够获取当前激活的邮件项,并读取其分类标签,展示了如何利用Outlook API进行邮件分类信息的检索。
2万+

被折叠的 条评论
为什么被折叠?



