Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 2nd, 2006, 10:39 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default CDONTS to CDOSYS

I rarely use asp but my employers are changing to Windows 2003 and have asked me to look into converting a validation script from CDONTS to CDOSYS, something I have never attempted, let alone have much idea about! Can anyone help please?

The script is;

<% Option Explicit %>
<%
Dim Item
Dim strTo, strFrom, strSubject, strBody
Dim strRequiredFields, strRequiredField, lRequiredDelimPos
Dim strOrderFields, strOrderField, lOrderDelimPos
Dim strSuccessPage, strErrorPage
Dim bError, strErrorMessage, strMailError

'-- Reset the errors
bError = false
strErrorMessage = ""

'-- Retrieve action variables
strTo = Request.Form("to")
strFrom = Request.Form("from")
strSubject = Request.Form("subject")
strRequiredFields = Request.Form("required-fields")
strOrderFields = Request.Form("field-order")
strSuccessPage = Request.Form("success-page")
strErrorPage = Request.Form("error-page")

'-- Retrieve the email values
If strOrderFields <> "" Then
     ' split strOrderFields into form fields
     Do Until InStr(strOrderFields,",") = 0

          'extract the field
          lOrderDelimPos = InStr(strOrderFields, ",")
          strOrderField = Left(strOrderFields, lOrderDelimPos - 1)

          ' Add form value to the email
          strBody = strBody & strOrderField & ": " & Request.Form(strOrderField) & vbCrLf & vbCrLf

          'strip off field text from order fields and reset delimitor position --
          strOrderFields = Right(strOrderFields, Len(strOrderFields) - lOrderDelimPos)
          lOrderDelimPos = 0
     Loop

    ' Add last form value to the email
     If strOrderFields <> "" Then
          strBody = strBody & Trim(strOrderFields) & ": " & Request.Form(Trim(strOrderFields)) & vbCrLf & vbCrLf
     End if
Else
     ' Loop through all the form values
     For each Item in Request.Form
          Select Case Item
          Case "to","from","subject","required-fields","ordered-fields","success-page","error-page"
               ' Do nothing
          Case Else
               ' Add form value to the email
               strBody = strBody & Item & ": " & Request.Form(Item) & vbCrLf & vbCrLf
          End Select
     Next
End If

'-- Validate the success page
If strSuccessPage = "" Then
     bError = True
     strErrorMessage = strErrorMessage & Server.HTMLEncode("No success page specified.") & "<br />"
End If

'-- Validate the error page
If strErrorPage = "" Then
     bError = True
     strErrorMessage = strErrorMessage & Server.HTMLEncode("No error page specified.") & "<br />"
End If

'-- Validate the recipient address
If strTo = "" Or Not IsValidEmail(strTo) Then
     bError = True
     strErrorMessage = strErrorMessage & Server.HTMLEncode("Invalid recipient email address: '" & strTo & "'.") & "<br />"
End If

'-- Validate the sender address
If strFrom = "" Or Not IsValidEmail(strFrom) Then
     bError = True
     strErrorMessage = strErrorMessage & Server.HTMLEncode("Invalid sender email address: '" & strFrom & "'.") & vbCrLf
End If

'-- Validate required fields
If strRequiredFields <> "" Then
     ' split strRequiredFields into validation fields
     Do Until InStr(strRequiredFields,",") = 0

          'extract the validation field
          lRequiredDelimPos = InStr(strRequiredFields, ",")
          strRequiredField = Left(strRequiredFields, lRequiredDelimPos - 1)

          'check the field
          If Request.Form(strRequiredField) = "" Then
               bError = True
               strErrorMessage = strErrorMessage & Server.HTMLEncode("Missing value for required '" & strRequiredField & "' field.") & "<br />"
          End if

          'strip off validation field text from text row and reset delimitor position --
          strRequiredFields = Right(strRequiredFields, Len(strRequiredFields) - lRequiredDelimPos)
          lRequiredDelimPos = 0
     Loop

     'check the last field
     If strRequiredFields <> "" Then
          If Request.Form(strRequiredFields) = "" Then
               bError = True
               strErrorMessage = strErrorMessage & Server.HTMLEncode("Missing value for required '" & strRequiredFields & "' field.") & "<br />"
          End if
     End if
End If

'Response.write "'" & strErrorMessage & "'<br />"
'Response.flush

'Response.write "Error " & Err.Number & ": " & Err.Description

'-- Check for errors
If bError = True Then
     '-- Redirect to the error page
     If strErrorPage <> "" Then
          Response.Redirect strErrorPage & "?ErrorMessage=" & strErrorMessage
     Else
          Response.Write "<html><head><title>Mail Error</title></head> " _
               & "<body> " _
               & "<h1>Errors</h1> " _
               & "" & strErrorMessage & " " _
               & "</body>"
     End If
Else
     '-- Send the mail
     strMailError = SendMail (strTo, strFrom, strFrom, "NORMAL", strSubject, strBody, "", False)

     If strMailError <> "" Then
          bError = True
          strErrorMessage = strErrorMessage & "Mail could not be sent. " & strMailError & vbCrLf
     End If

     '-- Redirect to the success or error page
     If bError = True Then
          Response.Redirect strErrorPage & "?ErrorMessage=" & strErrorMessage
     Else
          Response.Redirect strSuccessPage
     End If
End If

Function DoesFileExist(dfeFilePath)
     Dim fs
     Set fs=Server.CreateObject("Scripting.FileSystemObject ")

     DoesFileExist = fs.FileExists( dfeFilePath)

     set fs=nothing
End Function

Function IsValidEmail(strEmail)
     ' Checks that email addresses are of the format
     ' "user@domain.com"

     Dim bIsValid
     bIsValid = True

     'Check for minimum length of 1 leter, at sign, one letter, dot, one letter
     If Len(strEmail) < 5 Then
          bIsValid = False
     Else
          'Check that email address includes no spaces
          If Instr(1, strEmail, " ") <> 0 Then
               bIsValid = False
          Else
               'Check that email address include at sign
               If InStr(1, strEmail, "@", 1) < 2 Then
                    bIsValid = False
               Else
                    'Check that email address includes at least one dot after the at sign
                    If InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) + 2 Then
                         bIsValid = False
                    End If
               End If
          End If
     End If

     IsValidEmail = bIsValid
End Function

Function SendMail(sTo, sFrom, sReplyTo, sPriority, sSubject, sBody, sAttachment, bHTML)
'On Error Resume Next
     Const cdoLow = 0 ' Low importance
     Const cdoNormal = 1 ' Normal importance (default)
     Const cdoHigh = 2 ' High importance

     Const cdoBodyFormatHTML = 0
     Const cdoBodyFormatText = 1
     Const cdoMailFormatMime = 0
     Const cdoMailFormatText = 1

     Dim oMailMessage

     ' Create a new mail object
     Set oMailMessage = Server.CreateObject("CDONTS.NewMail")

     ' Set a destination email address
     oMailMessage.To = sTo

     ' Set a From and Reply-TO email address
     oMailMessage.From = sFrom
     oMailMessage.Value("Reply-To") = sReplyTo

     ' Set the subject
     oMailMessage.Subject = sSubject

     ' Set the priority
     sPriority = ucase(sPriority)
     if sPriority = "LOW" then
          oMailMessage.importance = cdoLow
     elseif sPriority = "HIGH" then
          oMailMessage.importance = cdoHigh
     else
          oMailMessage.importance = cdoNormal
     end if

     ' Set body format for HTML if needed
     if bHTML then
          oMailMessage.BodyFormat = cdoBodyFormatHTML
          oMailMessage.MailFormat = cdoMailFormatMime
     else
          oMailMessage.BodyFormat = cdoBodyFormatText
          oMailMessage.MailFormat = cdoMailFormatText
     end if
     oMailMessage.Body = sBody

     ' Set attachment
     if sAttachment <> "" then
          oMailMessage.Attachfile sAttachment
     end if

     ' Now send it off!
     oMailMessage.Send

     set oMailMessage = nothing

     if Err then
          SendMail = "Error " & Err.Number & ": " & Err.Description
     else
          SendMail = ""
     end if

End Function
%>



Many thanks in advance,
Geoff

Reply With Quote
  #2 (permalink)  
Old March 2nd, 2006, 06:27 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Yes you need to convert - Win 2003 does not support CDONTS hoever you can download and register the CDONTS.dll file to make it work.

CDOSYS code (did you try google):
http://support.microsoft.com/default.aspx/kb/265527


Wind is your friend
Matt
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CDONTS and CDOSYS hamproof Classic ASP Databases 0 August 24th, 2007 01:37 PM
CDOSYS Bob Bedell Pro VB 6 1 February 14th, 2006 10:16 AM



All times are GMT -4. The time now is 02:59 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.