HOW TO: Get details about a Exchange User in Outlook 2007 & Outlook 2003

I recently came across an issue where I needed to get the details about Exchange User from within an Outlook Add-in. Below is a screen shot of the details I am referring to.


In Outlook 2007 its very simple, just use the ExchangeUser Object and you will get the details. More details can be found in the article below:

ExchangeUser Object Members

Below is sample C# code that shows how to use the ExchangeUser Object:

using System;
using System.Collections.Generic;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace GetUserDetails
    class Program
        static void Main(string[] args)
            Outlook.Application oApp;
            Outlook.NameSpace oNameSpace;
            Outlook.SelectNamesDialog oSNDialog;
            Outlook.AddressEntry oAEntry;
            Outlook.ExchangeUser oEUser;
            oApp = new Outlook.Application();
            oNameSpace = oApp.GetNamespace("MAPI");
            oNameSpace.Logon(null, null, true, false);  

            oSNDialog = oNameSpace.GetSelectNamesDialog();
            oSNDialog.NumberOfRecipientSelectors = Outlook.OlRecipientSelectors.olShowTo;
            oSNDialog.Caption = "Select User";
            oSNDialog.ToLabel = "User Name";
            oSNDialog.ShowOnlyInitialAddressList = true;
            oSNDialog.AllowMultipleSelection = false;
             foreach(Outlook.Recipient oRecipient in oSNDialog.Recipients)
                oAEntry = oRecipient.AddressEntry;
                if(oAEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry
                    || oAEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                    oEUser = oAEntry.GetExchangeUser();

                    oEUser = null;
                oAEntry = null;

            oNameSpace = null;

However in Outlook 2003 the ExchangeUser Object is not there. The only way to do it is query the AD based on the AddressEntry.Address(LegacyexchangeDN). Below is sample C# code that uses the DirectoryServices namespace to query the AD based on LegacyexchangeDN.

using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;

namespace GetUserDetailsBasedOnLegacyDN
    class Program
        static void Main(string[] args)
            //This is the legacy exchange DN
            string LEDN = "/O=ms/OU=east/cn=Recipients/cn=whatever";

            DirectoryEntry objRootDSE = new DirectoryEntry("GC://RootDSE");
            String strRoot = objRootDSE.Properties["rootDomainNamingContext"].Value.ToString();
            DirectoryEntry objRoot = new DirectoryEntry("GC://" + strRoot);

            DirectorySearcher objSrch = new DirectorySearcher(objRoot);
            objSrch.Filter = "(&(objectClass=user)(objectCategory=person)(legacyExchangeDN= " + LEDN + "))";
            objSrch.SearchScope = SearchScope.Subtree;
            DirectoryEntry objUser = new DirectoryEntry();
            objUser = objSrch.FindOne().GetDirectoryEntry();

            Console.WriteLine("Mobile:" + objUser.Properties["mobile"].Value);
            Console.WriteLine("Number:" + objUser.Properties["telephoneNumber"].Value);
            Console.WriteLine("Department:" + objUser.Properties["department"].Value);
            objUser = null;
            objSrch = null;
            objRoot = null;
            objRootDSE = null;

Note: I am not an AD expert, you might need to tweak the code depending on your environment and your needs.

Comments (6)

  1. Developer says:

    Thanks your example was useful to get the required details!!!

  2. Masoud forouzi says:

    I need to fetch Home Number of the exchange user,

    Could you help me ?

  3. Akashb says:

    Here you go!

    Outlook.PropertyAccessor oPA;

    String oHome1;

    oPA = oEUser.PropertyAccessor;

    //Get the Home Phone number

    oHome1 =(String)oPA.GetProperty("");


  4. Hi,

    I am also facing the same problem, can you help me out how to use above code. what are the variable component in code, which I have to replace in code according to my AD.

  5. Akashb says:

    The above code would work only for Outlook 2007. For Outlook 2003 you would have to use the "homePhone" property in the same way we query the "mobile" property.

  6. Jesse says:

    First I’d Like to thank you for giving this code for OL2007, I was looking around for quite some time.

    But I have prb using the OL2007 code, when I double click on the Recipient name in the list, the dialog box disappears. The only way i can add it to the TO or CC box is to select the recipient and click on "UserName"

    Is there a way to double click on the name and it gets added to the To or CC box??



Skip to main content