ASP 發送電子郵件



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="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
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="mymail@mydomain.com"
myMail. To="someone@somedomain.com"
myMail.Bcc="someoneelse@somedomain.com"
myMail.Cc="someoneelse2@somedomain.com"
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="mymail@mydomain.com"
myMail.To="someone@somedomain.com "
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="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
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 ="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
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="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
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="mymail@mydomain. com"
myMail.To="someone@somedomain.com"
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
%>

########