Sample script for CDO email

CDO (Collaboration Data Objects) is an inbuilt ASP component used to send emails via ASP. It is widely used as a CDONTs replacement, because Microsoft discontinued the use of CDONTs on Windows 2000, Windows XP and Windows 2003 OS. CDO is the best choice to send emails from ASP based web applications, as it comes pre-installed with server OS like, Windows Server 2003, 2008 and 2012.

If you are still using CDONT component in your ASP application to send emails, you should update your code to use CDO. Below is a basic CDO script you can use to send emails. It's just a basic script, and you may have to customize it according to your requirements. You can find lots of web pages on the internet with more customizations and attributes with CDO.


Const cdoSendUsingMethod = _
Const cdoSendUsingPort = 2
Const cdoSMTPServer = _
Const cdoSMTPServerPort = _
Const cdoSMTPConnectionTimeout = _
Const cdoSMTPAuthenticate = _
Const cdoBasic = 1
Const cdoSendUserName = _
Const cdoSendPassword = _
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
' Get a handle on the config object and it's fields
objConfig = Server.CreateObject("CDO.Configuration")
Fields = objConfig.Fields
' config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "mail server name"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "Email account "
.Item(cdoSendPassword) = "Password"
End With
objMessage = Server.CreateObject("CDO.Message")
objMessage.Configuration = objConfig
With objMessage
.To = "emailAddress"
.From = "emailAddress"
.Subject = "SMTP Relay Test"
.TextBody = "SMTP Relay Test Sent @ " & Now()
End With
Fields = Nothing
objMessage = Nothing
objConfig = Nothing

If you run into any problems while using this script, you can contact AccuWebHosting support with the exact error message or URL.

Note: You should always clean your email list using email verification tool before starting an email campaign.

Looking to send emails using CDONTS? Click on Send > CDO Email for more details.

Was this answer helpful?

« Back