E-mail lookup in active directory

How do I lookup the E-Mail entry in active dicetory using VB .Net 2005
LVL 2
ExtremeFitnessAsked:
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.

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

http://www.velocityreviews.com/forums/t91051-ldap-directoryentry.html

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()

Bob
0

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:
Bob,
Got it thanks :)

     Try
            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
       
0
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.