Support Center » Knowledgebase » How to send email using CDOSYS from your ASP script

How to send email using CDOSYS from your ASP script



CDONTS is no longer supported by Microsoft, and subsequently dropped from Windows 2003, existing code should be migrated to CDOSYS, the new API from Microsoft. This article presents an example that sends an email using CDOSYS.

In this code below, please replace mail.example.com to mail.yourdomain.com accordingly.
 
<%
' send by connecting to port 25 of the SMTP server
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim strSmartHost

Const cdoSendUsingPort = 2
StrSmartHost = "mail.example.com"

set iMsg = CreateObject("CDO.Message")
set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields

' set the CDOSYS configuration fields to use port 25 on the SMTP server

With Flds
  .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
  ' Use SMTP authentication 
  .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication 
  .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "emailaccount@yourdomain.com" 
  .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "emailpassword" 
  .Update
End With
' build HTML for message body
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "<b> This is the test HTML message body</b></br>"
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"

' apply the settings to the message
With iMsg
Set .Configuration = iConf
.To = "nrnoble@example.com"
.From = "nrnoble@example.com"
.Subject = "This is a test CDOSYS message (Sent via Port 25)"
.HTMLBody = strHTML
.Send
End With

' cleanup of variables
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

%>

The above example came from:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_clb_sending_smtp_mail_by_port_25_using_cdosys_vbs.asp



Article Details
Article ID: 88
Created On: 03 Oct 2004 05:00 AM
 Back
 Login [Lost Password] 
Email:
Password:
Remember Me:
Please note that the login and password to the support area is NOT the same as your hosting control panel login and password
 
 Search
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Downloads | Control Panel User's Guide | Server Status
Language: