cdo 发送html,ASP 使用 CDOSYS 发送电子邮件

使用 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="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 = "

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.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="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:\mydocuments\test.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

'远程 SMTP 服务器的 IP 或名称

myMail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/smtpserver") _

="smtp.server.com"

'服务器端口

myMail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _

=25

myMail.Configuration.Fields.Update

myMail.Send

set myMail=nothing

%>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 Classic ASP 和 SSL 发送电子邮件的示例代码: ``` <% Dim objMail Set objMail = Server.CreateObject("CDO.Message") ' Set up the email configuration objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your_email@gmail.com" objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your_password" objMail.Configuration.Fields.Update ' Set up the email content objMail.To = "recipient_email@example.com" objMail.From = "your_email@gmail.com" objMail.Subject = "Test Email" objMail.TextBody = "This is a test email sent using SSL." ' Send the email On Error Resume Next objMail.Send If Err.Number = 0 Then Response.Write "Email sent successfully." Else Response.Write "An error occurred: " & Err.Description End If Set objMail = Nothing %> ``` 请注意,您需要将上面的代码中的以下行替换为您自己的电子邮件地址和密码: ``` objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your_email@gmail.com" objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your_password" objMail.To = "recipient_email@example.com" objMail.From = "your_email@gmail.com" ``` 此外,您需要将 SMTP 服务器和端口设置为您使用电子邮件服务的设置。在上面的示例中,我们使用 Gmail 的 SMTP 服务器和端口。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值