How to: Obtain Members of an Exchange Distribution List
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Obtain Members of an Exchange Distribution List

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This example lets the user select an Exchange distribution list from the Select Names dialog box and expands the distribution list to display its members.

This code sample calls the GetExchangeDistributionListMembers method of the ExchangeDistributionList object to get an AddressEntries collection that contains all the members of the list. Because distribution lists can be nested inside another distribution list, the returned AddressEntries collection can represent any type of Exchange AddressEntry object.


Expanding distribution lists can create a performance burden on an Exchange server, so use the GetExchangeDistributionListMembers method cautiously. Expect that your code will be slow when it expands large distribution lists.

To obtain the members of a distribution list, the user must be connected to an Exchange server and online.

If you use Microsoft Visual Studio to test this code sample, you must first add a reference to the Microsoft Outlook 12.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The Imports or using statements must not occur right before the functions in the Code section but must be added before the public Class declaration. The following lines of code show how to do the import and assignment in Visual Basic and in C#:

using Outlook = Microsoft.Office.Interop.Outlook;
private void GetDistributionListMembers()
    Outlook.SelectNamesDialog snd =
    Outlook.AddressLists addrLists =
    foreach (Outlook.AddressList addrList in addrLists)
        if (addrList.Name == "All Groups")
            snd.InitialAddressList = addrList;
    snd.NumberOfRecipientSelectors =
    snd.ToLabel = "D/L";
    snd.ShowOnlyInitialAddressList = true;
    snd.AllowMultipleSelection = false;
    if (snd.Recipients.Count > 0)
        Outlook.AddressEntry addrEntry =
        if (addrEntry.AddressEntryUserType ==
            Outlook.ExchangeDistributionList exchDL =
            Outlook.AddressEntries addrEntries =
            if (addrEntries != null)
                foreach (Outlook.AddressEntry exchDLMember
                    in addrEntries)
© 2016 Microsoft