Print Page | Close Window

Send email from form entry

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=6220
Printed Date: 31 March 2026 at 5:13am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Send email from form entry
Posted By: twooly
Subject: Send email from form entry
Date Posted: 06 October 2003 at 6:08pm

I almost have this working except for a few bugs.  Basicly I want someone to enter their username and then the page will look up that entry and send the user their password to their email.  The problem I am having is specifying the TO Email based on the entry you get back from the DB and the Body containing that enties information.  Here is the code.  I highlighted the two lines in question. Any suggesstions?

Thanks

If Request.querystring("mode") = "get" then

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("toddwoolums_site.mdb")

strUserName = Request.Form("txtUserName")

IF strUserName = "" then
 Response.Redirect"password.asp?mode=blank"
End If

'Create an ADO recordset object
Set rsGetPassword = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT username, password, email from tblUsers where username = '" & strUserName & "'"

'Open the recordset with the SQL query
rsGetPassword.Open strSQL, adoCon

'Reset server objects

If rsGetPassword.EOF then
 Response.Redirect"password.asp?mode=nouser"
End If

Dim strEmail
strEmail = rsGetPassword("email")

Response.Write ("Username is ")
Response.Write (rsGetPassword("username"))
Response.Write ("<br><br><br>")
Response.Write ("Password is ")
Response.Write (rsGetPassword("password"))
Response.Write ("<br><br><br>")
Response.Write ("Email is ")
Response.Write (rsGetPassword("email"))
Response.Write ("<br><br><br>")

'Dimension variables
Dim objCDOMail      'Holds the CDONTS NewMail Object
'Create the e-mail server object
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
'Who the e-mail is from
objCDOMail.From = " mailto:twooly@mchsi.com - m ine@email.com"
'Who the e-mail is sent to
objCDOMail.To = rsGetPassword("email")
'Set the subject of the e-mail
objCDOMail.Subject = "Lost Password"
'Set the e-mail body format (0=HTML 1=Text)
objCDOMail.BodyFormat = 0
'Set the mail format (0=MIME 1=Text)
objCDOMail.MailFormat = 0
'Set the main body of the e-mail
objCDOMail.Body = "Password is: '" & rsGetPassword("password") "'"
'Importance of the e-mail (0=Low, 1=Normal, 2=High)
objCDOMail.Importance = 1
'Send the e-mail
objCDOMail.Send
'Close the server object
Set objCDOMail = Nothing

Set rsGetPassword = Nothing
Set adoCon = Nothing

End If




Replies:
Posted By: fernan82
Date Posted: 06 October 2003 at 6:18pm

So what's the problem???

<edit> I see one with this line:

objCDOMail.Body = "Password is: '" & rsGetPassword("password") "'"

should be:

objCDOMail.Body = "Password is: '" & rsGetPassword("password") & "'"



-------------
FeRnAN
http://www.danasoft.com/">


Posted By: twooly
Date Posted: 06 October 2003 at 6:24pm

Ok now I get this error.  I am also going to note that this is on a windows 2003 server and I don't know if it has cdonts.  IS there an easier way to do this?

Server object error 'ASP 0177 : 800401f3'

Server.CreateObject Failed

/password.asp, line 100

800401f3



Posted By: twooly
Date Posted: 06 October 2003 at 6:32pm

Ok I found a tutorial that might help. http://www.invisionportal.com/show_tutorial.asp?TutorialID=160 - http://www.invisionportal.com/show_tutorial.asp?TutorialID=1 60   So I changed my code to look like this.   But I am getting this error now line 124 is marked

error '8004020f'

/password.asp, line 124

'Dimension variables
Dim objCDOSYSCon
'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
'Set and update fields properties
'Out going SMTP server
objCDOSYSCon.Fields(" http://schemas.microsoft.com/cdo/configuration/smtpserver - http://schemas.microsoft.com/cdo/configuration/smtpserver ") = "mydomain.com"
'SMTP port
objCDOSYSCon.Fields(" http://schemas.microsoft.com/cdo/configuration/smtpserverport - http://schemas.microsoft.com/cdo/configuration/smtpserverpor t ")  = 25
'CDO Port
objCDOSYSCon.Fields(" http://schemas.microsoft.com/cdo/configuration/sendusing - http://schemas.microsoft.com/cdo/configuration/sendusing ") = 2
'Timeout
objCDOSYSCon.Fields(" http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout - http://schemas.microsoft.com/cdo/configuration/smtpconnectio ntimeout ") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
'Who the e-mail is from
objCDOSYSMail.From = " mailto:mine@email.com - mine@email.com "
'Who the e-mail is sent to
objCDOSYSMail.To = rsGetPassword("email")
'The subject of the e-mail
objCDOSYSMail.Subject = "Lost Password"
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
objCDOSYSMail.HTMLBody = "Password is: '" & rsGetPassword("password") & "'"
'Send the e-mail
objCDOSYSMail.Send
'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing



Posted By: fernan82
Date Posted: 06 October 2003 at 6:54pm

Ok, on the first one what is line 100? if it's this:

Set objCDOMail = Server.CreateObject("CDONTS.NewMail")

Then that means you don't have CDONTS registered on your server.

On the second one, make sure that you have an SMTP server, that you got the right address for your SMTP server and that you have permission to relay email on it. Also post the full error message.

 



-------------
FeRnAN
http://www.danasoft.com/">


Posted By: twooly
Date Posted: 06 October 2003 at 7:22pm

Ok CDONTS wasn't installed. 

My Test box wasn't letting me send through the local SMTP.  That is fixed now.  Thanks for all your help and sorry for being a pain.  I guess that is why I am a newbie.

 

Thanks again

--Todd




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net