View Full Version : CDONTS / CDOSYS WinXP

10-08-2003, 02:21 PM
I am using the CDONTS to send email on a event within a site, however we have ust changed servers (Now using XP) and CDONTS does not exist on WinXP. It has been replaced with CDOSYS. Now for short term I have registered CDONTS on the XP machine and all is fine, does anyone have any experience in changing over from NTS to SYS?

10-08-2003, 05:53 PM
Didn't even know there was a CDOSYS.

Just adding the cdonts.dll and using regsvr32 to register it is the easiest way for WinXP. :)

10-09-2003, 11:19 AM
CDOSYS is much more sophisticated then CDONTS, but if you've already got code using the latter and you've registered the DLL then there's little point in you changing your existing code.

However, perhaps you should start developing any *new* code with CDOSYS...

10-11-2003, 07:39 PM
Here's an example, "mail.myDomain.com" is the URL of the SMTP server:

set cdoMessage = Server.CreateObject("CDO.Message")
set cdoConfig = Server.CreateObject("CDO.Configuration")
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.myDomain.com"
set cdoMessage.Configuration = cdoConfig
cdoMessage.From = myFromAddr
cdoMessage.To = myRecipientList
cdoMessage.Subject = mySubject
cdoMessage.HtmlBody = myBody
on error resume next
if Err.Number <> 0 then
Response.Write("Email send failed: " & Err.Description & ".")
end if
set cdoMessage = Nothing
set cdoConfig = Nothing

You'll notice that in typical MS fashion, they've made a simple task even more difficult to accomplish.

10-11-2003, 08:01 PM
I don't think that's very fair. CDONTS was a very primitive (i.e. limited) version of CDOSYS, and it didn't even allow you to specify an SMTP server or the port (it only worked with an SMTP service running on the localhost on port 25)!!

Although perhaps more verbose, CDOSYS is far more sophisticated, and besides, who in their write mind would write that code out more than once? That's what functions and classes are for!

:p :D

Here's a class I wrote a while ago which neatly encapsulates CDOSYS - it's pretty self-explanatory, but if you have any questions, just ask. It's not complete (it lacks CC and BCC properties, and Property Get handlers) but they are easy enough to add if you need them.
Class clsEmail
Private Message, MSF
Const URL = "http://schemas.microsoft.com/cdo/configuration"

Private Sub Class_Initialize()
Set Message = Server.CreateObject("CDO.Message")
Set Message.Configuration = Server.CreateObject("CDO.Configuration")
Set MSF = Message.Configuration.Fields
MSF.Item(URL & "/sendusing") = 2
MSF.Item(URL & "/smtpserverport") = 25
MSF.Item(URL & "/smtpconnectiontimeout") = 10
End Sub

Private Sub Class_Terminate()
Set Message = Nothing
Set Configuration = Nothing
End Sub

Public Property Let ServerName(sName)
MSF.Item(URL & "/smtpserver") = sName
End Property

Public Property Let Port(sPort)
MSF.Item(URL & "/smtpserverport") = sPort
End Property

Public Property Let Timeout(sTimeout)
MSF.Item(URL & "/smtpconnectiontimeout") = sTimeout
End Property

Public Property Let [To](sTo)
Message.To = sTo
End Property

Public Property Let From(sFrom)
Message.From = sFrom
End Property

Public Property Let Subject(sSubject)
Message.Subject = sSubject
End Property

Public Property Let Body(sText)
Message.TextBody = sText
End Property

Public Sub Send()
End Sub
End Class

EDIT: Just made some code tweaks that I meant to make a while ago... it was written in a hurry...!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum