Testing CDOSYS Mail Functionality
Note: |
| The ASP code provided below is only an example. Your specific website may require different code. As outlined in our article Management and Support Levels, we are unable to troubleshoot code issues. We recommend speaking with a developer before implementing any ASP-based email functionality. |
ASP allows you to send emails using a functionality called CDOSYS. By creating email content and sending emails using ASP directly, you don’t have to add any extra components to your code.
We recommend that you use an SMTP relay that requires authentication. Because of stringent anti-spam filters, sending mail through unauthenticated SMTP servers (including the localhost relay on Cloud Sites) can result in delays or undelivered email.
Before you start using CDOSYS to send email, it’s a best practice to test your code. To test CDOSYS functionality, use the following code saved into a file with a .asp extension.
Example Code Using CDOSYS
The variables in this sample code are dependent on your specific website. You will need to replace the example values for the following variables:
- .Item(cdoSMTPServer)
- .Item(cdoSendUserName)
- .Item(cdoSendPassword)
- .To
- .From
These values will be highlighted in red in the code below. If you aren’t sure how to edit this code, please speak with your developer.
<%
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort = 2
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic = 1
Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
'Get a handle on the config object and its fields.'
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
'Set config fields we care about'
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "mail.(domain.com)"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "webmaster@example.com"
.Item(cdoSendPassword) = "yourPassword"
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.To = "Nobody <nobody@example.com>"
.From = "Web Master <webmaster@example.com>"
.Subject = "Test message using CDOSYS SMTP"
.TextBody = "This is a test email message using CDOSYS SMTP Sent @ " & Now()
.Send
End With
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing %>