title: Getting Email address from Active Directory
body: <p>All --</p>
  
  <p>I am able to retieve the FullName value
        I am trying to retrieve an email address from Active Directory but using the following code in my ASP.Net Web Forms project that is using Windows Authentication:</p>
  
  <pre><code>Dim wi As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
  Dim a As String() = wi.Name.Split(New Char() {"\"c}) '' Context.User.Identity.Name.Split('\')
  
  Dim ADEntry As System.DirectoryServices.DirectoryEntry = New System.DirectoryServices.DirectoryEntry(Convert.ToString("WinNT://" + a(0) + "/" + a(1)))
  Dim Name As String = ADEntry.Properties("FullName").Value.ToString()
  Dim Email As String = ADEntry.Properties("mail").Value.ToString()
  </code></pre>
  
  <p>when I get to the line of code where I'm try to retrieve the email address I get an "Object reference not set to an instance of an object." error. I have tried using EmailAddress, E-Mail. I think the problem is that I am simply using the wrong keyword. I am able to retrieve the FullName value.</p>