Latest web development tutorials

ASP 使用CDOSYS 發送電子郵件

CDOSYS 是ASP 中的內建組件。 此組件用於通過ASP 發送電子郵件。


使用CDOSYS 發送電子郵件

CDO (Collaboration Data Objects) 是一項微軟的技術,設計目的是用來簡化通訊應用程序的創建。

CDOSYS 是ASP 中的內建組件。 我們將向您演示如何通過ASP 使用該組件來發送電子郵件。

CDONTs 怎麼樣?

微軟已經在Windows 2000、Windows XP 和Windows 2003 中淘汰了CDONTs。 如果您已經在您的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.w3cschool.cc/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:mydocumentstest.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
%>