ASP 使用 CDOSYS 发送电子邮件

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="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.yapf.com/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
%>

相关文章