教程
CDOSYS是ASP中的内置组件。此组建用于通过ASP来发送电子邮件。
使用CDOSYS发送电子邮件
CDO (Collaboration Data Objects)是一项微软的技术,被设计用来简化通信程序的创建。
CDOCDOSYS是ASP中的内置组件。我们将会您展示如何使用该组件来发送电子邮件。
How about CDONTs?
微软已经在Windows 2000、Windows XP以及Windows 2003中淘汰了CDONTs。如果您还在应用程序中使用CDONTs,就需要更新代码,并使用新的CDO技术。
使用CDOSYS的实例
发送电子邮件:
<%Set myMail=CreateObject("CDO.Message")myMail.Subject="Sending email with CDO"myMail.From="mymailmydomain.com"myMail.To="someonesomedomain.com"myMail.TextBody="This is a message."myMail.Sendset myMail=nothing%>
使用Bcc和CC域来发送文本邮件:
<%Set myMail=CreateObject("CDO.Message")myMail.Subject="Sending email with CDO"myMail.From="mymailmydomain.com"myMail.To="someonesomedomain.com"myMail.Bcc="someoneelsesomedomain.com"myMail.Cc="someoneelse2somedomain.com"myMail.TextBody="This is a message."myMail.Sendset myMail=nothing%>
发送HTML邮件:
<%Set myMail=CreateObject("CDO.Message")myMail.Subject="Sending email with CDO"myMail.From="mymailmydomain.com"myMail.To="someonesomedomain.com"myMail.HTMLBody = "<h1>This is a message.</h1>" myMail.Sendset myMail=nothing%>
发送一封由网站传送网页的HTML邮件:
<%Set myMail=CreateObject("CDO.Message")myMail.Subject="Sending email with CDO"myMail.From="mymailmydomain.com"myMail.To="someonesomedomain.com"myMail.CreateMHTMLBody "http://www.webjx.com/" myMail.Sendset myMail=nothing%>
发送一封从您的电脑中的文件来传送网页的HTML邮件:
<%Set myMail=CreateObject("CDO.Message")myMail.Subject="Sending email with CDO"myMail.From="mymailmydomain.com"myMail.To="someonesomedomain.com"myMail.CreateMHTMLBody "file://c:/mydocuments/test.htm" myMail.Sendset myMail=nothing%>
发送一封带有附件的电子邮件:
<%Set myMail=CreateObject("CDO.Message")myMail.Subject="Sending email with CDO"myMail.From="mymailmydomain.com"myMail.To="someonesomedomain.com"myMail.TextBody="This is a message."myMail.AddAttachment "c:\mydocuments\test.txt"myMail.Sendset myMail=nothing%>
使用远程服务器发送一封文本邮件:
<%Set myMail=CreateObject("CDO.Message")myMail.Subject="Sending email with CDO"myMail.From="mymailmydomain.com"myMail.To="someonesomedomain.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 servermyMail.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/smtpserver") _="smtp.server.com"'Server portmyMail.Configuration.Fields.Item _("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _=25 myMail.Configuration.Fields.UpdatemyMail.Sendset myMail=nothing%>