Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP Sending Email with CDOSYS

ASP Sending Email with CDOSYS


CDOSYS is a built-in component in ASP. This component is used to send email through ASP.


Sending email with CDOSYS

CDO (Collaboration Data Objects) is a Microsoft technology designed to simplify the creation of messaging applications.

CDOSYS is a built-in component in ASP. We will show you how to use this component to send email through ASP.

What about CDONTs?

Microsoft has retired CDONTs in Windows 2000, Windows XP, and Windows 2003. If you are already using CDONTs in your ASP applications, you need to update your code to use the new CDO technology.

Examples of using CDOSYS

Sending a text email:

<%

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.Send

set myMail=nothing

%>

Sending a text email with Bcc and CC fields:

<%

Set myMail=CreateObject("CDO.Message")

myMail.Subject="Sending email with CDO"

myMail.From="mymail@mydomain.com"

myMail.To="someone@somedomain.com"

myMail.Bcc="someoneelse@somedomain.com"

myMail.Cc="someoneelse2@somedomain.com"

myMail.TextBody="This is a message."

myMail.Send

set myMail=nothing

%>

Sending an HTML email:

<%

Set myMail=CreateObject("CDO.Message")

myMail.Subject="Sending email with CDO"

myMail.From="mymail@mydomain.com"

myMail.To="someone@somedomain.com"

myMail.HTMLBody = "

This is a message.

"

myMail.Send

set myMail=nothing

%>

Sending an HTML email whose content is a web page from a website:

<%

Set myMail=CreateObject("CDO.Message")

myMail.Subject="Sending email with CDO"

myMail.From="mymail@mydomain.com"

myMail.To="someone@somedomain.com"

myMail.CreateMHTMLBody "http://www.w3cschool.cc/asp/"

myMail.Send

set myMail=nothing

%>

Sending an HTML email whose content is a web page from a file on your computer:

<%

Set myMail=CreateObject("CDO.Message")

myMail.Subject="Sending email with CDO"

myMail.From="mymail@mydomain.com"

myMail.To="someone@somedomain.com"

myMail.CreateMHTMLBody "file://c:/mydocuments/test.htm"

myMail.Send

set myMail=nothing

%>

Sending a text email with an attachment:

<%

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.AddAttachment "c:mydocumentstest.txt"

myMail.Send

set myMail=nothing

%>

Sending a text email using a remote 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

%>