ASP send email



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


Send Email Using CDOSYS

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

CDOSYS is a built-in component in ASP. We'll show you how to use this component with ASP to send email.

What about CDONTs?

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

Using an instance of CDOSYS

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

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

Send 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 = "<h1>This is a message.</h1>"
myMail.Send
set myMail=nothing
%>

Send an HTML email with the content of a web page on 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
%>

Send a web page whose content is a file on your computer HTML email:

<%
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
%>

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

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