开发者

VSTO outlook Add-in How can I retrieve a Exchange Distribution list members from outlook distribution list

I have VSTO Add-in that gets the recipient from the mailitem and save it in our user list. In case of exchange distribution list or exchange contact as a recipient it works fine by extracting smtp mail address from both of these. For this purpose outlook object model works.

but the problem arises when exchange distribution list is added as a member in the outlook distribution list and mail is sent to this local distribution list. Is there any way to extract smtp addresses of each contact from this nested distribution list.

So far I have user DistListItem.GetMember(i) Method to get a member of this distribution list. It provides a Recipient object and when i try to access a property member.Addre开发者_如何学JAVAssEntry.AddressEntryUserType from this object it throw an exception "The item could not be found". Does anyone knows how can i get a distribution list member type or entryId from this recipient object?


    private void GetDistributionListMembers()
{
    Outlook.SelectNamesDialog snd =
        Application.Session.GetSelectNamesDialog();
    Outlook.AddressLists addrLists =
        Application.Session.AddressLists;
    foreach (Outlook.AddressList addrList in addrLists)
    {
        if (addrList.Name == "All Groups")
        {
            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)
                {
                    Debug.WriteLine(exchDLMember.Name);
                }
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜