Script Example - Send Mail Using CDO for Windows and a Remote SMTP Service

ASP.NET Web Hosting on Cloud Spaces Platform
 
Here is a sample script using CDOSYS sending email thru a remote SMTP server:

<%
 
Set myMail=CreateObject("CDO.Message")
 
myMail.Subject="Sending email with CDO"
 
myMail.From="mymail@mydomain.com"
 
myMail.To="someone@somedomain.com"
 
myMail.TextBody="This is a message."
 
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
 
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") _="smtp.server.com"
 
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _=25 
 
myMail.Configuration.Fields.Update
 
myMail.Send
 
set myMail=nothing
 
%>

 
 
HOWTO: Send HTML Formatted Mail Using CDO for Windows and a Remote SMTP Service

' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML

Const cdoSendUsingPort = 2

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
'ToDo: Enter name or IP address of remote SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Update
End With

' Build HTML for message body.
strHTML = ""
strHTML = strHTML & ""
strHTML = strHTML & ""
strHTML = strHTML & " This is the test HTML message body
"
strHTML = strHTML & ""
strHTML = strHTML & ""

' Apply the settings to the message.
With iMsg
Set .Configuration = iConf
.To = "" 'ToDo: Enter a valid email address.
.From = "" 'ToDo: Enter a valid email address.
.Subject = "This is a test CDOSYS message (Sent via Port 25)"
.HTMLBody = strHTML
.Send
End With

' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

MsgBox "Mail Sent!"

Add Feedback