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:

This is the sound of settling.

    Set objCDO = CreateObject("CDO.Message")
    objCDO.Subject = "Update from Web App."
    objCDO.From = "Web App <[email protected]>"
    objCDO.To = "[email protected]"
    objCDO.TextBody = "Hello," & vbCrLf & vbCrLf & "A new order has been placed by " & userName & "."
    objCDO.Configuration.Fields.Item("") = 2 'cdoSendUsingPort (1 = local, 3 = Exchange)
    objCDO.Configuration.Fields.Item("") = ""
    objCDO.Configuration.Fields.Item("") = 25
    set objCDO = Nothing

Chrissy is a PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Posted in VBScript

Leave a Reply

Your email address will not be published. Required fields are marked *