从“全局地址列表” Outlook中获取所有分发列表以及分发列表WPF中的成员

时间:2019-03-13 11:11:38

标签: wpf

我正在编写一个新的应用程序,我需要从“全局地址列表”中找到Outlook中通讯组列表的所有成员。

找到所有分发列表之后,我需要找到分发列表的所有成员。

最后,我想获取该成员的所有信息(如联系表格)。

我找到了这段代码来查找通讯组列表的成员,但是问题是我需要从Outlook中选择通讯组列表,然后它将显示所有成员。 我想通过在之前输入分发列表的名称来自动执行此操作。

    private void GetDistributionListMembers()
    {
        gal = outlookApp.Session.GetGlobalAddressList();
        Outlook.SelectNamesDialog snd =
            outlookApp.Session.GetSelectNamesDialog();
        Outlook.AddressLists addrLists =
            outlookApp.Session.AddressLists;
        foreach (Outlook.AddressList addrList in addrLists)
        {
            if (addrList.Name == "My Distribution List")
            {
                snd.InitialAddressList = addrList;
                break;
            }
        }
        snd.NumberOfRecipientSelectors =
            Outlook.OlRecipientSelectors.olShowTo;
        snd.ToLabel = "D/L";
        snd.ShowOnlyInitialAddressList = true;
        snd.AllowMultipleSelection = false;
        snd.Display();
        if (snd.Recipients.Count > 0)
        {
            Outlook.AddressEntry addrEntry =
                snd.Recipients[1].AddressEntry;
            if (addrEntry.AddressEntryUserType ==
                Outlook.OlAddressEntryUserType.
                olExchangeDistributionListAddressEntry)
            {
                Outlook.ExchangeDistributionList exchDL =
                    addrEntry.GetExchangeDistributionList();
                Outlook.AddressEntries addrEntries =
                    exchDL.GetExchangeDistributionListMembers();
                if (addrEntries != null)
                    foreach (Outlook.AddressEntry exchDLMember
                        in addrEntries)
                    {
                        MessageBox.Show(exchDLMember.Name);
                    }
            }
        }
    }

有人可以帮我吗?我在Google中搜索了很多内容,但没有找到任何解决方案。

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我找到了一种解决方案,无需手动选择即可获取特定“分发列表”的所有成员,这是代码:

    private void GetDistributionListMembers()
    {
        gal = outlookApp.Session.GetGlobalAddressList();
        Outlook.SelectNamesDialog snd =
            outlookApp.Session.GetSelectNamesDialog();
        Outlook.AddressLists addrLists =
            outlookApp.Session.AddressLists;
        foreach (Outlook.AddressList addrList in addrLists)
        {
            if (addrList.Name == "My Distribution List")
            {
                snd.InitialAddressList = addrList;
                break;
            }
        }
        snd.NumberOfRecipientSelectors =
            Outlook.OlRecipientSelectors.olShowTo;
        snd.ToLabel = "D/L";
        snd.ShowOnlyInitialAddressList = true;
        snd.AllowMultipleSelection = false;
        snd.Recipients.Add("My Distribution List");
        snd.Recipients.ResolveAll();
        //snd.Display();
        if (snd.Recipients.Count > 0)
        {
            Outlook.AddressEntry addrEntry =
                snd.Recipients[1].AddressEntry;
            if (addrEntry.AddressEntryUserType ==
                Outlook.OlAddressEntryUserType.
                olExchangeDistributionListAddressEntry)
            {
                Outlook.ExchangeDistributionList exchDL =
                    addrEntry.GetExchangeDistributionList();
                Outlook.AddressEntries addrEntries =
                    exchDL.GetExchangeDistributionListMembers();
                if (addrEntries != null)
                    foreach (Outlook.AddressEntry exchDLMember
                        in addrEntries)
                    {
                        MessageBox.Show(exchDLMember.Name);
                    }
            }
        }
    }

我正在寻找一种解决方案,以获取某人有想法的联系人的所有信息(例如Adress,Manager等)。