How do I test CDOSYS SMTP functionality?


You can use the following code saved into a file with a .asp extension to test CDOSYS functionality; CDOSYS is a built-in component in ASP, so utilizing it from your ASP code takes no additional effort on your part.

We strongly recommend using an SMTP relay that requires authentication. Sending mail through unauthenticated SMTP servers (including the localhost relay on Cloud Sites) can result in delays or undelivered email due to stringent anti-spam filters.

Example using CDOSYS

You will need to change the following variables:

  • .Item(cdoSMTPServer)
  • .Item(cdoSendUserName)
  • .Item(cdoSendPassword)
  • .To
  • .From
<%
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 it's 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
%>

See Also



Was this content helpful?




© 2014 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER