标记来自经理的邮件项以供跟进
此代码示例展示了如何标记来自用户的经理的电子邮件项以供跟进。
示例
注意
下面的代码示例摘录自 Microsoft Office Outlook 2007 应用程序编程。
Microsoft Outlook provides a task flagging system in which certain Outlook items such as mail items or contact items can be flagged for follow-up. When you flag an Outlook item for follow-up, information about that Outlook item, along with other task-based information, is displayed on the To-Do Bar and Calendar navigation module in the Outlook user interface. The To-Do Bar is displayed as a vertical pane in a typical configuration of the Outlook explorer window. It contains a date navigator control, upcoming appointments, and items that have been flagged for follow-up. The To-Do Bar itself is not extensible, and you can set configuration options for the To-Do Bar only through the Outlook user interface. Flagging items allows to you organize and prioritize tasks and to-do items.
下面的代码示例为一组项目标记指定的跟踪时间间隔。 此代码示例使用 DAV 搜索和定位 (DASL) 查询,以筛选出使用经理姓名作为发件人的“IPM.NOTE”类型邮件,从而获取当前用户收件箱中来自当前用户的经理的所有项。 然后,此代码示例根据 Importance 属性的 OlImportance 值标记所有项。 通过使用 MarkAsTask(OlMarkInterval) 方法,将最重要的所有项目标记为当天跟踪,将一般重要的所有项目标记为本周跟踪。
注意
Importance 属性和 MarkAsTask 方法是 Item 对象成员。
如果使用 Visual Studio 测试此代码示例,必须先添加对 Microsoft Outlook 15.0 对象库组件的引用,并在导入 Microsoft.Office.Interop.Outlook 命名空间时指定 Outlook 变量。 不得将 using 语句直接添加到此代码示例中的函数前面,这个语句必须后跟公共类声明。 下面的代码行演示了如何在 C# 中执行导入和分配。
using Outlook = Microsoft.Office.Interop.Outlook;
private void DemoTaskFlagging()
{
const string PR_SENT_REPRESENTING_NAME =
"http://schemas.microsoft.com/mapi/proptag/0x0042001E";
const string PR_MESSAGE_CLASS =
"http://schemas.microsoft.com/mapi/proptag/0x001A001E";
Outlook.AddressEntry currentUser =
Application.Session.CurrentUser.AddressEntry;
if (currentUser.Type == "EX")
{
Outlook.ExchangeUser manager;
try
{
manager = currentUser.
GetExchangeUser().GetExchangeUserManager();
}
catch
{
Debug.WriteLine("Could not obtain user's manager.");
return;
}
if (manager != null)
{
string displayName = manager.Name;
string filter = "@SQL=" + "\""
+ PR_SENT_REPRESENTING_NAME + "\""
+ " = '" + displayName + "'" + " AND " + "\""
+ PR_MESSAGE_CLASS + "\"" + " = 'IPM.NOTE'";
Outlook.Items items =
Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderInbox).
Items.Restrict(filter);
foreach (Outlook.MailItem mail in items)
{
if (mail.Importance ==
Outlook.OlImportance.olImportanceHigh)
{
mail.MarkAsTask(Outlook.OlMarkInterval.olMarkToday);
mail.Save();
}
if (mail.Importance ==
Outlook.OlImportance.olImportanceNormal)
{
mail.MarkAsTask(Outlook.OlMarkInterval.olMarkThisWeek);
mail.Save();
}
}
}
}
}