Here's the solution I ended up with:
<%@language="vbscript" %>
<%
Option Explicit
Dim objRootDSE, strDNSDomain, objConnection, strQuery
Dim objRecordSet, strName, strDN
Dim strBase, strFilter, strAttributes
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use ADO to search Active Directory.
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties("User ID") = "domain\username"
objConnection.Properties("Password") = "password"
objConnection.Open "Active Directory Provider"
' Search for all user objects. Sort recordset by DisplayName.
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" &
Session("UID") & "))"
strAttributes = "mail"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
Set objRecordSet = objConnection.Execute(strQuery)
If objRecordSet.EOF Then
response.Write "bolox"
End If
' Loop through results
Do Until objRecordSet.EOF
response.Write "Email Address: " & objRecordSet.Fields("mail")
objRecordSet.MoveNext
Loop
' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
%>
I was told that the mail property is not always reliable, ie may not be
populated, and that the proxyaddresses field would be better, but that
returns a multi-value responsew which I can't seem to handle. Besides, mail
seems to work OK for me...
Thanks
Chris