如何通过 Active Directory 从 Recipients 属性中获取 ContactItem。当收件人保存在本地联系人中时,我已经尝试了代码并获得了 ContactItem seccsussful。当收件人仅存在于 Active Directory 中时如何获取 ContactItem。
公共无效Application_ItemSend(对象邮件,参考布尔取消){
Outlook.MAPIFolder fldContacts = (Outlook.MAPIFolder)Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
for (int i = 1; i < mail.Recipients.Count + 1; i++)
{
Outlook.Recipient r = mail.Recipients.Item(i);
if (!r.Resolved) r.Resolve();
if (r.Resolved)
{
Outlook.ContactItem ci = (fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);
if (ci != null)
{
//to get the Department of Recipient
string DepartmentName = ci.Department;
}
}
}
}