Solved

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

Posted on 2006-06-23
6
364 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prevent URL from printing on header 5 65
Age between date range query (SP) 13 52
SQL Filter Question 8 77
Summernote required 3 101
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…
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 teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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