Latest web development tutorials

ASP menggunakan CDOSYS untuk mengirim e-mail

CDOSYS adalah komponen built-in di ASP. Komponen ini digunakan untuk mengirim e-mail melalui ASP.


Gunakan CDOSYS untuk mengirim e-mail

CDO (Kolaborasi Data Objects) adalah teknologi Microsoft, yang dirancang untuk menyederhanakan pembuatan aplikasi komunikasi.

CDOSYS adalah komponen built-in di ASP. Kami akan menunjukkan cara untuk menggunakan komponen ASP untuk mengirim email.

CDONTS bagaimana?

Microsoft memiliki CDONTS Windows 2000, Windows XP dan Windows 2003 dieliminasi. Jika Anda sudah menggunakan CDONTS aplikasi ASP Anda, Anda harus memperbarui kode Anda, dan menggunakan teknologi CDO baru.

Contoh CDOSYS

Mengirim pesan teks e-mail:

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.TextBody="This is a message."
myMail.Send
set myMail=nothing
%>

Kirim email teks dengan bidang Bcc dan CC:

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.Bcc="[email protected]"
myMail.Cc="[email protected]"
myMail.TextBody="This is a message."
myMail.Send
set myMail=nothing
%>

Kirim e-mail HTML:

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.HTMLBody = "<h1>This is a message.</h1>"
myMail.Send
set myMail=nothing
%>

Kirim konten dari sebuah halaman situs HTML e-mail:

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.CreateMHTMLBody "http://www.w3cschool.cc/asp/"
myMail.Send
set myMail=nothing
%>

Kirim isi halaman di komputer Anda dalam file HTML e-mail:

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.CreateMHTMLBody "file://c:/mydocuments/test.htm"
myMail.Send
set myMail=nothing
%>

Kirim email teks dengan lampiran:

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.TextBody="This is a message."
myMail.AddAttachment "c:mydocumentstest.txt"
myMail.Send
set myMail=nothing
%>

Menggunakan server remote untuk mengirim teks e-mail:

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
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
%>