ASP/VBScript: Send E-Mail with CDO

I’ve used CDONTS for years, even though it hasn’t been included in a Windows Server release since NT4. Anytime I needed to send mail, I’d copy over CDONTS.dll, register it then use my old CDONTS code. Not sure why I resisted it for so long.. I think the weird Configuration Fields were too odd to accept. But I’ve finally accepted them.. about 3 good years after ASP went out of style. Here’s a less-than-timely code snippet:


Set objCDO = CreateObject(“CDO.Message”)
objCDO.Subject = “Update from Web App.”
objCDO.From = “Web App
objCDO.To = “[email protected]
objCDO.TextBody = “Hello,” & vbCrLf & vbCrLf & “A new order has been placed by ” & userName & “.”
objCDO.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2 ‘cdoSendUsingPort (1 = local, 3 = Exchange)
objCDO.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “mail.me.com”
objCDO.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
objCDO.Configuration.Fields.Update
objCDO.Send
set objCDO = Nothing

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, holds a master's degree in Systems Engineering and is coauthor of Learn dbatools in a Month of Lunches. Chrissy is certified in SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in VBScript

Leave a Reply