CDOSYS is a legacy component enabled by default on our servers. It is the primary method for sending email from Classic ASP pages. While it can be used in older ASP.NET applications, we recommend using System.Net.Mail for any modern .NET development.
Before proceeding, ensure you have created a mailbox to obtain your SMTP server address and credentials.
Use the following code to send email from a .asp page. This script configures the CDO Message object to use the local SMTP server with authentication.
<%
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
'Configuration Constants
Const cdoSendUsingPort = 2
Const cdoBasicAuth = 1
'Get the configuration fields
Dim iConf
Set iConf = ObjSendMail.Configuration.Fields
'Set the configuration
With iConf
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.yourdomain.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
'Authentication (Required)
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasicAuth
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "info@yourdomain.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "YourPassword"
.Update
End With
'Create the message
With ObjSendMail
.To = "recipient@external.com"
.From = "info@yourdomain.com" 'Must match the authenticated username
.Subject = "Test Email from Classic ASP"
.TextBody = "This is a test email sent using CDOSYS."
.Send
End With
Set ObjSendMail = Nothing
%>
Note: This uses the obsolete System.Web.Mail namespace. For new applications, please use the System.Net.Mail method.
using System.Web.Mail;
// Configure the MailMessage object
MailMessage eMail = new MailMessage();
eMail.From = "info@yourdomain.com"; // Must match SMTP user
eMail.To = "recipient@external.com";
eMail.Subject = "Legacy CDO Test";
eMail.BodyFormat = MailFormat.Text;
eMail.Body = "This is a test.";
// CDO Configuration Fields
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "smtp.yourdomain.com";
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = 25;
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
// Authentication
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "info@yourdomain.com";
eMail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "YourPassword";
// Send
SmtpMail.SmtpServer = "smtp.yourdomain.com";
SmtpMail.Send(eMail);