Migrating CDONTS e-mail

The implementation of the CDONTs e-mail method used in asp has changed in Windows 2003 server.

Example old CDONTS implementation

 Set m1 = CreateObject("CDONTS.NewMail")
 m1.From = fromAddr
 m1.To = recipients
 m1.Subject = subject
 m1.Body = CStr("" & body)
 m1.Send

The code below is an example of the new cdo format.

 Set objErrMail= Server.CreateObject("CDO.Message")
 With objErrMail
 .From = fromAddr
 .To = recipients
 .Subject = subject
 .HTMLBody = CStr("" & body)
 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "myWebServer.com"
 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
 .Configuration.Fields.Update
 .Send
 End With

Note the sendusing schema has options as follows:

   use localhost
   use specified mail server

In our experience a value of 1 is simpler to configure.

The code below has been used to send e-mails via a remote SMTP server. Note the first line omits the word “server” as this is run as a local vbscript.

 Set objErrMail=CreateObject("CDO.Message")
 With objErrMail
 .From = myaddress@myaddress.com
 .To = myfriend@hisaddress.com
 .Subject = "Type in your subject here"
 .HTMLBody = "Type in the body of your message here"
 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'use 1 for local or 2 for remote smtp server
 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserveraddress.com" 'enter your smtp server
 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'port number 25 is standard
 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'use 0 for no auth, 1 for basic
 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myusername" ' enter your email username
 .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword" 'enter email password
 .Configuration.Fields.Update
 .Send
 End With