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:
1Set objCDO = CreateObject("CDO.Message")
2objCDO.Subject = "Update from Web App."
3objCDO.From = "Web App "
4objCDO.To = "[email protected]"
5objCDO.TextBody = "Hello," & vbCrLf & vbCrLf & _
6 "A new order has been placed by " & userName & "."
7
8objCDO.Configuration.Fields.Item("https://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort (1 = local, 3 = Exchange)
9objCDO.Configuration.Fields.Item("https://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.me.com"
10objCDO.Configuration.Fields.Item("https://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
11objCDO.Configuration.Fields.Update
12
13objCDO.Send
14Set objCDO = Nothing