• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 741
  • Last Modified:

E-mail lookup in active directory

How do I lookup the E-Mail entry in active dicetory using VB .Net 2005
0
ExtremeFitness
Asked:
ExtremeFitness
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now