ASP Gửi e-mail bằng CDOSYS
CDOSYS là một thành phần tích hợp trong ASP. Thành phần này được sử dụng để gửi e-mail với ASP.
Gửi email bằng CDOSYS
CDO (Đối tượng dữ liệu cộng tác) là một công nghệ của Microsoft được thiết kế để đơn giản hóa việc tạo các ứng dụng nhắn tin.
CDOSYS là một thành phần tích hợp trong ASP. Chúng tôi sẽ hướng dẫn bạn cách sử dụng thành phần này để gửi e-mail với ASP.
Còn CDONT thì sao?
Microsoft đã ngừng sử dụng CDONT trên Windows 2000, Windows XP và Windows 2003. Nếu bạn đã sử dụng CDONT trong các ứng dụng ASP của mình, bạn nên cập nhật mã và sử dụng công nghệ CDO mới.
Ví dụ sử dụng CDOSYS
Gửi e-mail văn bản:
<%
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
%>
Gửi e-mail văn bản có trường Bcc và 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
%>
Gửi 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
%>
Gửi e-mail HTML gửi một trang web từ một trang web:
<%
Set myMail = CreateObject("CDO.Message")
myMail.Subject = "Sending email with CDO"
myMail.From = " [email protected] "
myMail.To =" [email protected] "
myMail.CreateMHTMLBody "https://www.example.com.vn/asp/"
myMail.Send
set myMail = nothing
%>
Gửi e-mail HTML gửi trang web từ một tệp trên máy tính của bạn:
<%
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
%>
Gửi e-mail văn bản có tệp đính kèm:
<%
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
%>
Gửi e-mail văn bản bằng máy chủ từ xa:
<%
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 _
("https://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("https://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com"
'Server port
myMail.Configuration.Fields.Item _
("https://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
myMail.Configuration.Fields.Update
myMail.Send
set myMail = nothing
%>