You are here: irt.org | FAQ | ASP | Q1281 [ previous next ]
Enter your email address, click submit and this ASP code searches through an online access database for the email address entered by the user and then emails a Userid and Password to the email address in the database. This is done with the use of CDO - the Collaborative Data Object. This code assumes you have an online access database with a userid column, password column and an email column.
<%
'Set variable email to input box value
Email=Trim(request("email"))
accessdb="/PathTo/YourAccessDatabase.mdb"
myDSN="DRIVER={Microsoft Access Driver (*.mdb)};"
myDSN=myDSN & "DBQ=" & server.mappath(accessdb)
mySQL="Select * from YourTable where Email='" & Email & "'"
Dim CNN
Dim RST
Set CNN = server.CreateObject("ADODB.CONNECTION")
Set RST = server.CreateObject("ADODB.RECORDSET")
CNN.OPEN mydsn
rst.open mysql, CNN
'Search database for email address. If found, you can display
'the userid and password associated with the email address and/or you
'can email it using the email address from the database
if NOT RST.EOF Then
'Display UserID and Password
response.write "UserID: " & rst("username") & "<BR>"
response.write "Password: " & rst("password")
'Prepare the Email
Dim objCDO
Set objCDO = Server.CreateObject("CDONTS.NewMail")
'Include a prepared message
Dim txtSubject
txtSubject = "Hello, isn't this cool? Bye!"
'Basic Send Options
objCDO.To = "someone@somewhere.com"
objCDO.From = "123@abc.com"
objCDO.cc = "abc@123.com"
objCDO.bcc = "someone@somewhere.com"
objCDO.Subject = "Great ASP Script"
'If sending prepared message
objCDO.Body = txtSubject
'If sending UserID and Password
objCDO.Body = "UserID and Password: " & rst("username") & rst("password")
'Now Send it
objCDO.Send
'No matching email address found? Aww...
else
response.write "I'm sorry, we don't have that email address.
response.write "<p></p>"
response.write "<a href=forgot.asp>Return</a>"
end if
CNN.Close()
set RST = nothing
set Conn = nothing
set objCDO = nothing
%>Submitted by Marc W.