Solved

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

Posted on 2006-06-23
6
367 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Classic ASP - problem with MS SQL Select Query? 10 60
Questions about INCLUDE FILES 2 37
Button to go back 3 28
key press alert 2 32
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 information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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