Need specific LDAP query

Posted on 2006-04-04
Last Modified: 2010-04-18
The situation is this: a programmer is trying to set up an ASP page that grabs a user's name from their current session and use that to query AD to get that user's email address. So what I am looking for is the LDAP query that would pull the email address from AD based on their username, if there is one. I have seen queries to find users who are mail enabled or have an email address, but none that pulls the actual address.

Not to be a jerk, but...
Please supply only the query or a page relevant to this query. Do not link me to KB articles about LDAP or pages with LDAP syntax that are pointless or irrelevant please.  I just want to know if there is a query and how to find it. Thank you.
Question by:pearlvision
    LVL 19

    Accepted Solution

    Hi pearlvision,

    The below code will grab the full name and email address of the user accessing the page...

            'Get the domain identity of the user hitting the site
            Dim dUser As String =
            Dim i As Integer
            'Find the backslash
            i = dUser.IndexOf("\")
            'Extract the username from the domain name
            Dim uName As String = dUser.Substring(i + 1).Trim
            'Do a directory search for the username
            Dim dSearch As DirectorySearcher = New DirectorySearcher("(anr=" &
    uName & ")")
            Dim sResult As SearchResult
            'Assign the search result
            sResult = dSearch.FindOne()
            'Assign to the variables
            Dim fullName As String = sResult.Properties("name")(0)
            userEmail = sResult.Properties("mail")(0)

    LVL 6

    Assisted Solution

    by:Giuseppe De Francesco
    I think that this link can be useful to have a bit more:

    Have fun ;)


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
    by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now