从通讯组列表 WPF 中的 Outlook 和成员"Global Adress List"获取所有通讯组列表



我正在编写一个新应用程序,我需要在Outlook中找到"全局adress"列表中的分布列表中的所有成员。

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

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

我找到了此代码来查找分布列表的成员,但是问题是我需要从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中搜索了很多,但没有找到任何解决方案。

非常感谢您的帮助。

我找到了一个解决方案,可以在不手动选择的情况下获取特定"分布列表"的所有成员,以下是代码:

    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,...)有人有一个想法吗?

相关内容

  • 没有找到相关文章

最新更新