E-mail lookup in active directory

How do I lookup the E-Mail entry in active dicetory using VB .Net 2005
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
1) Set up a DirectorySearcher with a filter for objectCategory=person and sAMAccountName=userID

2) Get a DirectoryEntry from the search result.

3) Get the "mail" property from the DirectoryEntry.

ExtremeFitnessAuthor Commented:
Would you have code snippets?
Bob LearnedCommented:
Here is a simplified example:


Dim de As New DirectoryEntry("LDAP://CN=csaran,CN=User,
OU=Computer Services,DC=domain,DC=co,DC=uk")
Dim email As String = de.Properties("mail").Value.ToString()


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ExtremeFitnessAuthor Commented:
Got it thanks :)

            Dim oEntry As New DirectoryServices.DirectoryEntry("LDAP://mydoamin.com")
            Dim oSearcher As New System.DirectoryServices.DirectorySearcher(oEntry)
            oSearcher.Filter = ("(anr= " & username & ")")
            Dim oResult As SearchResult = oSearcher.FindOne()
            Dim propertyCount As Integer = oResult.Properties("mail").Count
            Return oResult.Properties("mail")(0)

        Catch ex As Exception
            Return ""
        End Try
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.