Sending Email from ASP using CDOSYS
CDOSYS is a legacy Microsoft component used to send email from classic ASP pages. While still supported on many Windows hosting platforms, it is not recommended for new projects. Use this sample code only if your site runs on classic ASP.
Sample CDOSYS Code
Const cdoSendUsing = 2
Const cdoBasic = 1
Const cdoNTLM = 2
Set objMessage = Server.CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "me@mydomain.com"
objMessage.To = "recipient@test.com"
objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication."
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.mydomain.com"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "me@mydomain.com"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
objMessage.Configuration.Fields.Update
objMessage.Send
Important Notes
- Replace
mail.mydomain.comwith your actual SMTP server hostname. - Use your full email address as the username (e.g.
email@domain.com). - Enter your email account password in the configuration.
- Enable SSL and use port 465 or 587 if your host requires secure connections.
⚠ Legacy Notice: CDOSYS is outdated. For modern ASP.NET applications, use
System.Net.Mail or an external SMTP relay service instead.