Avatar of mhouldridge
mhouldridge
 asked on

LDAP problem with retrieving email addresses

Experts,

I have the following LDAP query which retrieves all of the email addresses associated with a domain, in Actve Directory.  This works fine, however secondary email addresses are not detected, ie.  a user might have 5 attached email addresses, but the primary one is only retrieved.  How would I get all email addresses for each Active Directory object ( Users, Contact, Group etc..)???
System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry("LDAP://" + dom);
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=*)");
 
foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
     try
     {
          System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();
          string emailaddress = de.Properties["Mail"].Value.ToString();
          Console.WriteLine(emailaddress.ToString());
     }
     catch (Exception ex)
     {
     }
}

Open in new window

C#

Avatar of undefined
Last Comment
mhouldridge

8/22/2022 - Mon
mhouldridge

ASKER
Just checked, and I believe the Active Directory wording for the other mailboxes is called...

otherMailbox

I've added this however it does not show the other user mailbox addresses?
ASKER CERTIFIED SOLUTION
mhouldridge

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck