View Full Version : emaling details from an access DB

09-02-2005, 12:32 AM
Hi i have a system to email users their password if they forget it.
The data is stored in a access db.
it reading in their userid from a textbox
finds it in the DB
then emails the "password" to the users registered "email"

'Dimension variables
Dim adoCon 'Database Connection Variable
Dim strCon 'Holds the Database driver and the path and name of the database
Dim rsCheckDB 'Database Recordset Variable
Dim strAccessDB 'Holds the Access Database Name
Dim strSQL 'Database query sring
Dim strUserName2 'Holds the user name

'Initalise the strUserName2 variable
strUserName2 = Request.Form("txtUserName2")

'Check the database to see if user exsits
'Initialise the strAccessDB variable with the name of the Access Database
strAccessDB = "users"

'Create a connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

'Database connection info and driver
strCon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=letmein; DBQ=" & Server.MapPath(strAccessDB)

'Set an active connection to the Connection object
adoCon.Open strCon

'Create a recordset object
Set rsCheckDB = Server.CreateObject("ADODB.Recordset")

'Initalise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tblUsers.UserID, tblUsers.Password, tblUsers.Email FROM tblUsers WHERE tblUsers.UserID ='" & strUserName2 & "'"

'Query the database
rsCheckDB.Open strSQL, strCon

'If the recordset finds a record for the username entered then read in the password for the user
If NOT rsCheckDB.EOF Then

' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject

' get posted data into variables
EmailFrom = "someemail@hotmail.com"
EmailTo = rsCheckDB("Email")
Subject = "User Reminder Service"

' prepare email body text
Dim Body
Body = "Dear"& rsCheckDB("UserID")& VbCrLf & VbCrLf
"This message has been sent to you because you requested it, if you did not request it please contact us as soon as possible." & VbCrLf
& VbCrLf
"The Details you requested are as follows:" & VbCrLf
"Username:" rsCheckDB("UserID")& VbCrLf
"Password" rsCheckDB("Password")& VbCrLf
"If you still persist in haveing trouble accessing your 'client area' of the website, please contact us by email or phone."& VbCrLf
& VbCrLf
"Thank You" & VbCrLf
"Support & VbCrLf

' send email
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.To = EmailTo
mail.From = EmailFrom
mail.Subject = Subject
mail.Body = Body

'Close Objects before redirecting
Set adoCon = Nothing
Set strCon = Nothing
Set rsCheckDB = Nothing
'Redirect to the authorised user page and send the users name

' redirect to success page

End If

'Redirect to the unautorised user page

09-02-2005, 06:06 AM
Hi and welcome to the board!

Thanks for showing your code. Not sure if there was a question in there somewhere. I did notice that you're using CDONTS.

CDO is generally used instead of CDONTS on IIS 5 and after (actually the SMTP service within IIS) which is generally on servers after Win NT4 (although I think CDONTS is sometimes still supported too).

Here's a quickie memo to myself about converting my old CDONTS code to CDO:

o Change objCDONTS to be called objCDO (actually this is just a cosmetic change)

o This:
Set objCDONTS = Server.CreateObject("CDONTS.NewMail")

Changed to this instead:
Set objCDO = Server.CreateObject("CDO.Message")

o This:
objCDONTS.Body = strEmailBody

Changed to this instead:
objCDO.TextBody = strEmailBody

o This removed:
' Importance.
' (0=Low, 1=Normal, 2=High)
objCDONTS.Importance = 1

09-04-2005, 05:05 PM
o This removed:
' Importance.
' (0=Low, 1=Normal, 2=High)
objCDONTS.Importance = 1

You can still set importance in CDO just use this

With objCDO.Fields

' for Outlook:
.Item(cdoImportance) = cdoHigh
.Item(cdoPriority) = cdoPriorityUrgent

' for Outlook Express:
.Item("urn:schemas:mailheader:X-Priority") = 1

End With

09-06-2005, 12:49 PM
Hi miranda

Can u tell me how to set Read reciept in CDONTS Emails


09-06-2005, 02:07 PM
objCDONTS.Value("Disposition-Notification-To") = "me@myisp.com"

in CDO
objCDO.Fields(cdoDispositionNotificationTo) = "me@myisp.com"
objCDO.Fields(cdoReturnReceiptTo) = "me@myisp.com"