|
zipler -> Retrieve E-mail address from AD (5/12/2006 14:01:23)
|
I have a website that is using the following code to retrieve a username from AD and then it uses the username to "guess" the persons e-mail address. This works most of the time, but we do have an increasing number of people whos e-mail addresses no longer match their login. ****Here is the code from the main ASP which uses an include to retrieve 2 variables from another ASP. </td><td width=50%> <!-- #include virtual="/forms/tools/UserNameTEST.asp"--> <input type="hidden" name="SubmitName" value="<%= strdisplayname %>"> <input type="hidden" name="SubmitEmail" value="<%= strUserName %>@test.com"> <%= strdisplayname %> (<%= strUserName %>@test.com) </font> ****Here is the Second ASP which does the work. <% 'Function GetNames ' strUsername is the network login ' strdisplayname is the name (last, first) 'Option Explicit Dim strUsername,strdisplayname,con,rsu,Com,objADsPath,objDomain strUsername = LCase(Request.ServerVariables("auth_user")) strUserName = Right(strUserName, Len(strUserName) - InStrRev(strUserName, "\")) Set objDomain = GetObject ("GC://rootDSE") objADsPath = objDomain.Get("defaultNamingContext") Set objDomain = Nothing Set con = Server.CreateObject("ADODB.Connection") con.provider ="ADsDSOObject" con.Properties("User ID") = "OurDomain\QueryLogin" con.Properties("Password") = "password" con.open "Active Directory Provider" Set Com = CreateObject("ADODB.Command") Set Com.ActiveConnection = con Com.CommandText ="select displayname FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'" Set rsu = Com.Execute strdisplayname = rsu("displayname") rsu.Close con.Close Set rsu = Nothing Set con = Nothing 'End Function %> Basically, what I would like to do is get it to pull the e-mail address stored in active directory rather than using the user name. I believe I can change the following line and have what is returned assigned to strUserName but I do not know what I should select from objADsPath to return the e-mail. Com.CommandText ="select displayname FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'" If anyone could help me out that would be great!.. Thank you! Also, if it helps at all we are running Exchange 2003.
|
|
|
|