how to get ContactItem from Recipients property by Active directory. I had trid the code and get the ContactItem seccsussful when the Recipients is saved in local contact. how to get the ContactItem when a Recipients was only exists only on Active directory.
public void Application_ItemSend(object mail, ref bool Cancel) {
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;
}
}
}
}