Solved

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

Posted on 2006-06-23
6
366 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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