Hi,
Some comments.
1. If you know "mail" is populated, use it.
2. You don't need to specify a userID and password unless you are running
the code with an account that does not have permisssion to read the
attributes.
3. To read a multi-valued attribute, you can loop through the collection
with a "For Each" loop. However, you must account for the possibility that
the attribute will have no values. For example:
' Retrieve a multi-valued attribute .
strAttributes = "proxyAddresses"
Do Until adoRecordset.EOF
colMail = adoRecordset.Fields("proxyAddresses")
If IsEmpty(colMail) Then
' The attribute is empty (has no values).
Response.Write "No Email address"
Else
' The attribute has one or more values - enumerate.
For Each strMail In colMail
Response.Write "Email Address: " & strMail
Next
End If
Loop
--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site -
http://www.rlmueller.net
--
"CJM" <cj*******@newsgroups.nospam> wrote in message
news:eN**************@TK2MSFTNGP15.phx.gbl...
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)(sAMAc countName="
& 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