Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

How to: Enumerate the Entries in the Global Address List

This example enumerates the first 100 primary Simple Mail Transfer Protocol (SMTP) addresses in the Global Address List (GAL).

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

In the following code example, the SMTP address for an AddressEntry object is obtained by casting it to an ExchangeUser or ExchangeDistributionList object in a call to the GetExchangeUser() or GetExchangeDistributionList() methods. If the AddressEntry object represents an Exchange user, EnumerateGAL returns an ExchangeUser object that exposes properties of the AddressEntry object. Use ExchangeUser properties such as JobTitle, Department, Alias, BusinessTelephoneNumber, or PrimarySmtpAddress to expose them.

If you use Microsoft Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 14.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void EnumerateGAL()
    Outlook.AddressList gal =
    if (gal != null)
        for (int i = 1; 
            i <= Math.Min(100, gal.AddressEntries.Count - 1); i++)
            Outlook.AddressEntry addrEntry =
            if (addrEntry.AddressEntryUserType ==
                || addrEntry.AddressEntryUserType ==
                Outlook.ExchangeUser exchUser =
                Debug.WriteLine(exchUser.Name + " "
                    + exchUser.PrimarySmtpAddress);
            if (addrEntry.AddressEntryUserType ==
                Outlook.ExchangeDistributionList exchDL =
                Debug.WriteLine(exchDL.Name + " "
                    + exchDL.PrimarySmtpAddress);

Other Resources

Community Additions

© 2014 Microsoft. All rights reserved.