最新的Web開發教程
 

ASP發送電子郵件與CDOSYS


CDOSYS是ASP內置組件。 該組件被用來發送電子郵件與ASP​​。


發送電子郵件與CDOSYS

CDO (Collaboration Data Objects)是旨在簡化的消息傳遞應用程序創建一個微軟的技術。

CDOSYS是ASP內置組件。 我們將告訴你如何使用這個組件來發送電子郵件與ASP​​。

如何CDONTS?

微軟已停止使用CDONTS在Windows 2000,Windows XP和Windows 2003。如果你已經在你的ASP應用程序中使用CDONTS,則應該更新代碼,並使用新的CDO技術。

使用CDOSYS示例

發送文本電子郵件:

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

發送文本電子郵件與BCC和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
%>

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

發送HTML格式的電子郵件發送從網站中的網頁:

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

發送HTML電子郵件從你的計算機上的文件發送一個網頁:

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

發送文本郵件帶有附件:

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

發送使用遠程服務器的文本電子郵件:

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