Replacing CDONTS with CDOSYS, while can be time consuming for a large classic ASP application, is actually very easy to do. Here’s a simple example of what need to be changed at a minimum:
-
Set oCDOMail = Server.CreateObject(“CDONTS.NewMail”) to:
Set oCDOMail = Server.CreateObject(“CDO.Message”) - Remove BodyFormat property, oCDOMail.BodyFormat = 0 since it’s unnecessary.
- Replace MailFormat property oCDOMail.MailFormat = 0 with MimeFormatted property oCDOMail.MimeFormatted = True.
- You may also want to add Charset property.
oCDOMail.BodyPart.Charset = “utf-8” - Replace oCDOMail.Body with oCDOMail.HTMLBody.
- Replace Importance property oCDOMail.Importance = 1 with oCDOMail.Fields(“urn:schemas:mailheader:priority”).Value = 1
The typical page composition to send email using either object can be seen below:
CDONTS
<% Dim oCDOMail Set oCDOMail = Server.CreateObject("CDONTS.NewMail") oCDOMail.From = ... oCDOMail.To = ... oCDOMail.Subject = "CDONTS email" oCDOMail.BodyFormat = 0 oCDOMail.MailFormat = 0 oCDOMail.Importance = 1 oCDOMail.Body = "<html><body><p>This is a test.</p></body></html>" oCDOMail.Send Set oCDOMail = Nothing %>
CDO
<% Dim oCDOMail Set oCDOMail = Server.CreateObject("CDO.Message") oCDOMail.From = ... oCDOMail.To = ... oCDOMail.Subject = "CDO email" oCDOMail.BodyPart.Charset = "utf-8" oCDOMail.MimeFormatted = True oCDOMail.Fields("urn:schemas:mailheader:priority").Value = 1 oCDOMail.HTMLBody = "<html><body><p>This is a test.</p></body></html>" oCDOMail.Send Set oCDOMail = Nothing %>
And here’s the two pages compared side-by-side:
Since CDONTS was deprecated since Windows 2000, ideally, all applications still using it should be rewritten to use the newer CDO object. However, it’s very common to see many enterprises prefer to make CDONTS work on the newer Windows Server to save time and money from re-writing their legacy applications.