navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Retrieve E-mail address from AD

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> Retrieve E-mail address from AD
Page: [1]
 
zipler

 

Posts: 2
Joined: 5/12/2006
Status: offline

 
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.
zipler

 

Posts: 2
Joined: 5/12/2006
Status: offline

 
RE: Retrieve E-mail address from AD - 5/12/2006 19:35:50   
The fix was even easier than I thought. I opened up the Active Directory Schema editor to find the name of the variable I needed to pull

changed the following

Com.CommandText ="select displayname FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
Set rsu = Com.Execute
strdisplayname = rsu("displayname")


to

Com.CommandText ="select mail FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
Set rsu = Com.Execute
strdisplayname = rsu("mail")

Of course, I eneded up also adding in a simple left function to remove the @test.com so strdisplayname would still function the way it should in all of the forms. (since there are several hundred using the same include statement)


Thanks!

(in reply to zipler)
rdouglass

 

Posts: 9167
From: Biddeford, ME USA
Status: offline

 
RE: Retrieve E-mail address from AD - 5/12/2006 23:45:31   
Thanks much for posting your solution. It does help others a lot. :)

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to zipler)
JohnH

 

Posts: 43
Joined: 12/1/2004
Status: offline

 
RE: Retrieve E-mail address from AD - 1/31/2008 12:40:44   
This is a great bit of code. Does anyone know how it can be adapted so that I can use it to populate a drop down box with all my users on my domain?

Many thanks,

John

(in reply to zipler)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> Retrieve E-mail address from AD
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts