Solved

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

Posted on 2006-06-23
6
362 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now