ASP Mengirim email dengan CDOSYS


CDOSYS adalah komponen bawaan di ASP. Komponen ini digunakan untuk mengirim email dengan ASP.


Mengirim email dengan CDOSYS

CDO (Collaboration Data Objects) adalah teknologi Microsoft yang dirancang untuk menyederhanakan pembuatan aplikasi perpesanan.

CDOSYS adalah komponen bawaan di ASP. Kami akan menunjukkan cara menggunakan komponen ini untuk mengirim email dengan ASP.

Bagaimana dengan CDONT?

Microsoft telah menghentikan penggunaan CDONT pada Windows 2000, Windows XP dan Windows 2003. Jika Anda telah menggunakan CDONT dalam aplikasi ASP, Anda harus memperbarui kode dan menggunakan teknologi CDO yang baru.

Contoh menggunakan CDOSYS

Mengirim email teks:

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

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

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

Mengirim email HTML yang mengirim halaman web dari situs web:

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


Mengirim email HTML yang mengirim halaman web dari file di komputer Anda:

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

Mengirim 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:\mydocuments\test.txt"
myMail.Send
set myMail = nothing
%>

Mengirim email teks menggunakan server jauh:

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