0

如何通过 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;
                    }
                }
            }

    }
4

2 回答 2

0

只需更改如下代码:

Outlook.ContactItem ci = (fldContacts.Items.Find("[Email1Address] = '" + r.Address + "'") as Outlook.ContactItem);

更改为 ExchangeUser contactItem = recip.AddressEntry.GetExchangeUser();

于 2018-11-26T07:14:02.233 回答
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();

                    }
                }

            }
        }

有关更多信息,请参阅此链接:

C# Outlook 从 Recipient 获取 CompanyName 属性

于 2018-11-26T06:25:02.543 回答