最新的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
%>