如何通过Active Directory从收件人属性获取ContactItem。当收件人保存在本地联系人中时,我已经尝试过编码并让ContactItem保密。仅当Active Directory上存在收件人时如何获取ContactItem。
public void 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;
}
}
}
}
答案 0 :(得分:0)
您可以参考以下代码:
bool resolved;
Microsoft.Office.Interop.Outlook.Application olApplication = new Microsoft.Office.Interop.Outlook.Application();
// get nameSpace and logon.
Microsoft.Office.Interop.Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi");
olNameSpace.Logon("Outlook", "", false, true);
// get the Calender items
Microsoft.Office.Interop.Outlook.MAPIFolder _olCalender = olNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
// Get the Items (Appointments) collection from the Calendar folder.
Microsoft.Office.Interop.Outlook.Items oItems = _olCalender.Items;
foreach (object o in oItems)
{
if (o is Microsoft.Office.Interop.Outlook.AppointmentItem)
{
Microsoft.Office.Interop.Outlook.Recipients recipients = ((Microsoft.Office.Interop.Outlook.AppointmentItem)o).Recipients;
foreach (Microsoft.Office.Interop.Outlook.Recipient rec in recipients)
{
resolved = rec.Resolve();
if (resolved)
{
Microsoft.Office.Interop.Outlook.ContactItem contactItem = rec.AddressEntry.GetContact();
}
}
}
}
有关更多信息,请参考此链接:
答案 1 :(得分:0)
只需更改以下代码:
Outlook.ContactItem ci = (fldContacts.Items.Find(“ [Email1Address] ='” + r.Address +“'”)as Outlook.ContactItem);
更改为 ExchangeUser contactItem = recip.AddressEntry.GetExchangeUser();