Sample Code for Sending Email Using CDO with SMTP Authentication
Classic ASP applications can still send email using CDO (Collaboration Data Objects), although CDO is now deprecated in modern Windows Server versions. Many legacy applications continue to rely on it, and the following example shows how to send authenticated SMTP email using CDO.
Make sure you update the SMTP server, username, and password with your actual email account details.
Updated CDO Sample Code
<%
Const cdoSendUsingPort = 2
Const cdoBasic = 1
Set objMessage = Server.CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "me@your-domain-name.com"
objMessage.To = "recipient@test.com"
objMessage.TextBody = "This is a sample message sent using SMTP authentication."
' SMTP configuration
With objMessage.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your-domain-name.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "me@your-domain-name.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With
objMessage.Send
Set objMessage = Nothing
%>
Important: Many modern mail servers now require SSL/TLS and port 587 instead of port 25. Update these values according to your provider’s requirements.
Notes
- Replace mail.your-domain-name.com with your actual SMTP hostname.
- Use your full email address as the SMTP username.
- Use your mailbox password for authentication.
- Most providers now require SSL/TLS and port 587.
- CDO is deprecated, but still works on Windows Server 2012–2022 when installed.
For new development, consider switching to a modern mail library such as ASP.NET’s System.Net.Mail or an API-based service like SendGrid or Mailgun.
Learn More About Fast2host
Fast2host has been providing reliable UK hosting, domains, cloud servers and business email since 2002. Find out more about who we are:
About Fast2host →