ASP 使用 CDOSYS 发送电子邮件

CDOSYS 是 ASP 中的内置组件。此组建用于通过 ASP 来发送电子邮件。

使用 CDOSYS 发送电子邮件

CDO (Collaboration Data Objects) 是一项微软的技术,设计目的是用来简化通信程序的创建。

CDOSYS 是 ASP 中的内置组件。我们将会您展示如何使用该组件来发送电子邮件。

CDONTs 怎么样?

微软已经在 Windows 2000、Windows XP 以及 Windows 2003 中淘汰了 CDONTs。如果您还在应用程序中使用 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.w3school.com.cn/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
%>