Solved

Help with modifying script to use cdosys rather than cdonts (unsupported)

Posted on 2006-06-23
6
368 Views
Last Modified: 2008-01-09
Hi,
  This ASP script should email the user their password in the event they've forgotten it. My server doesn't support the CDONTS email component.  Can someone point me in the right direction for modifying the script to use the CDOSYS component. I'm way out of my element (recklessly assuming I have one) and have tried a few dozen tutorials..

<%
Dim UsersRS__value
UsersRS__value = "0"
If (Request("Email") <> "") Then
  UsersRS__value = Request("Email")
End If
%>
<%
Dim UsersRS
Dim UsersRS_numRows
Set UsersRS = Server.CreateObject("ADODB.Recordset")
UsersRS.ActiveConnection = MM_CharonCart_STRING
UsersRS.Source = "SELECT *  FROM Customers  WHERE CustomerEmail='" + Replace(UsersRS__value, "'", "''") + "' "
UsersRS.CursorType = 0
UsersRS.CursorLocation = 2
UsersRS.LockType = 3
UsersRS.Open()
UsersRS_numRows = 0
%>
<%
if Request("Selected") <> "" then
UserEmail=Request("Email")
if not UsersRS.eof then
UserPassword=UsersRS("CustomerPassword")
SendEmail
Response.Redirect "forgotten_password.asp?success=true"
else
Response.Redirect "forgotten_password.asp?failed=true"
end if
end if
      function SendEmail
            Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
            objCDOMail.From = "CustomerService@neatgift.com"
            objCDOMail.To = UserEmail
            objCDOMail.Subject = "Forgotten Password for Neat Gift"
            objCDOMail.Body = mailbody
            objCDOMail.Send
            Set objCDOMail = Nothing
      end function

function mailbody
tmpstr=""
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.validateOnParse=True
objXML.load(Server.MapPath("xml/forgot_password.xml"))
set objNodeXML=objXML.documentElement
tmpstr=objNodeXML.selectSingleNode("body").Text
Set objXML = Nothing
tmpstr=replace(tmpstr,"#UserEmail#",UserEmail)
tmpstr=replace(tmpstr,"#UserPassword#",UserPassword)
mailbody=tmpstr
end function
%>

Thanks, Gary
0
Comment
Question by:AROC
6 Comments
 
LVL 11

Expert Comment

by:walkerke
ID: 16972790
What does your server support for email?
0
 
LVL 11

Expert Comment

by:walkerke
ID: 16972795
Better question, what type of server are you using?
0
 

Author Comment

by:AROC
ID: 16973622
ASPmail and CDOSYS I believe. The site is set up on an asp server (if that's what you were asking) with the referenced db and connection string working in other capacities.

This code is from the servers help file for CDOSYS:

<!--METADATA TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library" -->
<!--METADATA TYPE="typelib"
UUID="00000205-0000-0010-8000-00AA006D2EA4"
NAME="ADODB Type Library" -->
<%
Dim objMail
Set objMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")

'Configuration:
objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort

objConfig.Fields(cdoSMTPServer)="smtp.1and1.com"
objConfig.Fields(cdoSMTPServerPort)=25
objConfig.Fields(cdoSMTPAuthenticate)=cdoBasic
objConfig.Fields(cdoSendUserName) = "mxxxxxxxx-x"
objConfig.Fields(cdoSendPassword) = "xxxxxxxx"

'Update configuration
objConfig.Fields.Update
Set objMail.Configuration = objConfig

objMail.From ="info@justonedomain.com"
objMail.To = "support@1and1.com"
objMail.Subject ="Information"
objMail.TextBody="This is a test for CDO.message"
objMail.Send

If Err.Number = 0 Then
  Response.Write("Mail sent!")
Else
  Response.Write("Error sending mail. Code: " & Err.Number)
  Err.Clear
End If
Set objMail=Nothing
Set objConfig=Nothing
%>

And this for ASPmail:

<%
Set Mail = Server.CreateObject("SMTPsvg.Mailer") 'create an Asp mail component.
Mail.FromName   = "1&1 Test"
Mail.FromAddress= Request.Form("email")
Mail.RemoteHost = "mrelay.perfora.net" ' The mail server you have to use with Asp Mail
Mail.AddRecipient "ABCDE Company", "hello@justonedomain.com"
Mail.Subject    = "Website - Info Request"
Mail.BodyText   = Request.Form("info")
if Mail.SendMail then
 Response.Write "Your mail has already been sent..."
else
 Response.Write "Mail send failure. Error was " & Mail.Response
end if
%>

Thanks for the help,
Gary

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 16

Assisted Solution

by:CWS (haripriya)
CWS (haripriya) earned 50 total points
ID: 16974095
AROC,

I f your problem is still not solved please go through the article about send emails using CDOSYS.

http://www.w3schools.com/asp/asp_send_email.asp
0
 
LVL 21

Accepted Solution

by:
ap_sajith earned 350 total points
ID: 16974497
Use the generic subroutine below to send out emails using CDOSYS.

<%
' Usages
'CALL SendMailCDOSYS("a@b.com","c@d.com","test",strMailBody,True,"localhost","admin","password")
CALL SendMailCDOSYS("a@b.com","c@d.com","test",strMailBody,True,"localhost","","")

Sub SendMailCDOSYS(strFrom,strTO,strSubject,strMailBody,blnHTML,sMailServer,sUid,sPwd)
On Error Resume Next
Dim objCDOConf,objCDOSYS
' ** CREATE THE E-MAIL SERVER OBJECT **
Set objCDOSYS = Server.CreateObject("CDO.Message")
Set objCDOConf = Server.CreateObject ("CDO.Configuration")

' ** SET AND UPDATE FIELDS PROPERTIES **
With objCDOConf    
      ' ** OUT GOING SMTP SERVER **
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = sMailServer
      ' ** SMTP PORT **
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")  = 25
      ' ** CDO PORT **
      .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' cdoSendUsingPort
      ' ** TIMEOUT **
      .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      
      ' Check if SMTP Authentication is required
      If sUid<>"" Then
            ' ** AUTHENTICATION MECHANISM **
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic
            ' The username for authenticating to an SMTP server
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = sUid
            ' The password used to authenticate to an SMTP server
            .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = sPwd
      End If
      .Fields.Update
End With

' ** UPDATE THE CDOSYS CONFIGURATION **
Set objCDOSYS.Configuration = objCDOConf

With objCDOSYS    
      ' ** WHO THE E-MAIL IS FROM **
      .From = strFrom

      ' ** WHO THE E-MAIL IS SENT TO **
      .To = strTo

      ' ** THE SUBJECT OF THE E-MAIL **
      .Subject = strSubject

      ' ** SET THE E-MAIL BODY FORMAT (HTMLBody=HTML TextBody=Plain) **
      If blnHTML = True Then
            .HTMLBody = strMailBody
      Else
            .TextBody = strMailBody
      End If

      ' ** SEND THE E-MAIL **
      .Send
End with                    

'Cleanup
Set objCDOConf = Nothing
Set objCDOSYS = Nothing
End Sub
%>

I use the above subroutine in all my asp apps. I normally keep the subroutine in a separate page ('fn_mail.asp') and include the page where ever I require email functionality.

Cheers!
0
 

Author Comment

by:AROC
ID: 16976631
Thanks to all who take the time to try and help.

This link also helps newer users (which I am) understand the basics.

http://webthang.co.uk/tuts/tuts_dmx04/mailers/mailers1.asp
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
html Uncheck Checkbox 2 30
Asp in server side with Mssql Server 7 4 34
href return to normal window 5 31
SQL to JSON 14 40
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question