日照市东港区创新电子技术中心
ndfweb.cn

用CDONTS.NewMail发邮件


2008-12-24 16:36:45 (7830)


<%
'Last Updated By Recon On 05/14/2001
'On Error Resume Next

'利用CDONTS组件在Win2k上发送邮件
Dim objMail

'普通邮件
'无主体
Set objMail = Server.CreateObject("CDONTS.NEWMAIL")
objMail.From        = "iamchn@263.net"
objMail.To            = "iamchn@21cn.com"
objMail.Subject    = "TEST1"
objMail.Send
Set objMail = Nothing

'普通邮件
'有主体
Set objMail = Server.CreateObject("CDONTS.NEWMAIL")
objMail.From        = "iamchn@263.net"
objMail.To            = "iamchn@21cn.com"
objMail.Subject    = "TEST2"
objMail.Body        = "When i was young, i listened to the radio ..."
objMail.Send
Set objMail = Nothing

'普通邮件
'有多送.有主体
Set objMail = Server.CreateObject("CDONTS.NEWMAIL")
objMail.From        = "iamchn@263.net"
objMail.To            = "iamchn@21cn.com;iamchn@263.net"
objMail.Subject    = "TEST3"
objMail.Body        = "When i was young, i listened to the radio ..."
objMail.Send
Set objMail = Nothing

'普通邮件
'有抄送.有主体.有重要性
Set objMail = Server.CreateObject("CDONTS.NEWMAIL")
objMail.From        = "iamchn@263.net"
objMail.To            = "iamchn@21cn.com"
objMail.Cc            = "iamchn@263.net;recon_chan@sohu.com"
objMail.Subject    = "TEST4"
objMail.Body        = "When i was young, i listened to the radio ..."
objMail.Importance = 2
objMail.Send
Set objMail = Nothing

'普通邮件
'有抄送.有暗送.有主体.有重要性
Set objMail = Server.CreateObject("CDONTS.NEWMAIL")
objMail.From        = "iamchn@263.net"
objMail.To            = "iamchn@21cn.com"
objMail.Cc            = "recon_chan@sohu.com"
objMail.Bcc             = "iamchn@263.net;recon_chan@sina.com"
objMail.Subject    = "TEST5"
objMail.Body        = "When i was young, i listened to the radio ..."
objMail.Importance = 2
objMail.Send
Set objMail = Nothing

'普通邮件
'有主体.有重要性.含附件
Set objMail = Server.CreateObject("CDONTS.NEWMAIL")
objMail.From        = "iamchn@263.net"
objMail.To            = "iamchn@21cn.com"
objMail.Subject    = "TEST6"
objMail.Body        = "When i was young, i listened to the radio ..."
objMail.Importance = 2

objMail.AttachFile "C:\Love.txt"
objMail.Send
Set objMail = Nothing

'HTML邮件
'有主体.有重要性
'注: AttachURL的使用可能有错误
Dim fso, tf
Dim strHTML

Set fso    = Server.CreateObject("SCRIPTING.FILESYSTEMOBJECT")
Set tf    = fso.OpenTextFile("C:\Mail.htm", 1)
strHTML = tf.ReadAll

Write strHTML
Set tf    = Nothing
Set fso    = Nothing

Set objMail = Server.CreateObject("CDONTS.NEWMAIL")
objMail.From        = "iamchn@263.net"
objMail.To            = "iamchn@21cn.com"
objMail.Subject    = "TEST7"
objMail.Body        = strHTML

objMail.BodyFormat    = 0
objMail.MailFormat    = 0
objMail.Importance    = 2

objMail.AttachURL "c:\common.css", "common.css"
objMail.AttachURL "c:\logo.gif", "logo.gif"
objMail.Send
Set objMail = Nothing
%>

////////////////
一个过程。另外CDONTS在IIS5下才可以使用的,你还必须配置你的SMTP服务,在INTERNET管理器里面有。
<%
sub sendmail(fromwho,towho,subject,body)
dim cdo
set cdo=server.createobject("cdonts.newmail")
cdo.From=fromwho
cdo.To = towho
cdo.Subject =subject
cdo.Body =body
cdo.MailFormat=0
'说明是以MIME发送
cdo.BodyFormat=0
'可以包含html代码
cdo.Importance=0
'邮件的优先级别0-1-2
'cdo.cc=xx@xx.net 抄送
'cdo.Bcc=xx@sf.net密送
'cdo.AttachFile "" 附件
cdo.Send
Set cdo=Nothing
end sub
sub sendattachmail(fromwho,towho,subject,body,attachfile)
dim cdo
set cdo=server.createobject("cdonts.newmail")
cdo.From=fromwho
cdo.To = towho
cdo.Subject =subject
cdo.Body =body
cdo.MailFormat=0
cdo.BodyFormat=0
cdo.Importance=0
cdo.AttachFile attachfile
cdo.Send
Set cdo=Nothing
end sub
%>
发送带附件的HTML格式邮件例程


  如何通过 ASP 来发送带附件、格式为 HTML 的邮件?下面提供了一个例程.

<%@ LANGUAGE=VBScript%>
<%
Response.Buffer = True
Response.Expires = 0

'创建对象实例
Set myMail = Server.CreateObject("CDONTS.NewMail")

'以下是将要发送的内容
HTML = "<html>"
HTML = HTML & "<head>"
HTML = HTML & "<title>Sending CDONTS Email Using HTML</title>"
HTML = HTML & "</head>"
HTML = HTML & "<body bgcolor=""FFFFFF"">"
HTML = HTML & "<p><font size=7>"
HTML = HTML & "This is a test mail in html<br>"
HTML = HTML & "Mail content here ...</font></p>"
HTML = HTML & "</body>"
HTML = HTML & "</html>"

'发件人
myMail.From = "somebody@somewhere.com"

'收件人
myMail.To = "nobody@somewhere.com"

'密件抄送
myMail.Bcc = "nobody@somewhere.com"

'抄送
myMail.Cc = "nobody@somewhere.com"

'邮件的重要性
' 0 重要性低 
' 1 重要性一般(默认)
' 2 重要性高 
myMail.Importance = 2

'邮件主题
myMail.Subject = "Test mail in HTML"

'附件(注意 e:\test.txt 指的是服务器上的位置,如果使用相对路径,必须用 Server.MapPath 映射为真实路径)
myMail.AttachFile "e:\test.txt"

'NewMail 对象的文字格式
'0 表示该 Body 可包含超文本置标语言 (HTML)
'1 表示该 Body 只用于纯文本(默认值)
myMail.BodyFormat = 0

'NewMail 对象设置编码
'0 表示将采用 MIME 格式
'1 表示将采用连续的纯文本(默认值)
myMail.MailFormat = 0

'给邮件对象的文本赋值
myMail.Body = HTML

'将邮件发出
myMail.Send

'销毁对象实例,释放内存
Set myMail = Nothing
%>


用Cdonts实现发送Email 

--------------------------------------------------------------------


<%
  dim cdo
  set cdo=server.createobject("cdonts.newmail")
  cdo.From=fromwho   "发件人信箱
  cdo.To = towho     "收件人信箱
  cdo.Subject =subject    "主题
  cdo.Body =body      "邮件正文
  cdo.MailFormat=0  "说明是以MIME发送
  cdo.BodyFormat=0  "可以包含html代码
  cdo.Importance=0  "邮件的优先级别0-1-2
  cdo.cc=xx@xx.net   "抄送
  cdo.Bcc=xx@sf.net  "密送
  cdo.AttachFile attachfile    "附件
  cdo.Send
  Set cdo=Nothing
%>
下面我们看一个实例:
dim str 
str=str&"您好!"
str=str&"  由中国学生网所提供的劣质服务(ASP服务器瘫痪),导致本站连继两天不能访问。"
str=str&"站长向这段时间不能访问本站的朋友深表歉意!本工作室也正在考虑更换网络提供商!<br>"
str=str&"  本站永久域名:www.chinabs.net  主要面向B/S技术爱好者。<br>"
str=str&"  建站的目的是为B/S爱好者提供一个学习交流的平台,同时也为商家建立企业上网平" str=str&"台,企业内部B/S应用提供解决方案。<br>"
str=str&"  主要内容包括:ASP,ASP.NET,JSP,PHP,C#,Java,JavaScript,XML学习文章,B/S技术" str=str&"交流论坛及一些本工作室开发的一些B/S应用。<br>"
str=str&"  本站的发展离不开大家的支持!<br>"
str=str&"  谢谢!<br>"
str=str&" 站长:追风<br>"
str=str&" 深圳比艾思工作室<br>"
filename="test.gif"           "附件文件名
path=Server.MapPath("\jefenet\images\" & filename)     "附件的路径
Set theMail=Server.CreateObject("CDONTS.NewMail")
theMail.From="chinabs@263.net"   "发件人信箱
theMail.To ="jeffzb@21cn.com"   "收件人信箱
theMail.Subject ="电子邮件功能测试!"   "主题
theMail.BodyFormat=0   "定义以Html的格式发送邮件
theMail.MailFormat=0    "定义以Mime的格式发邮件
theMail.Body=Str      "邮件正文
On Error Resume Next       "如果找不到附件,则跳过
theMail.AttachFile path,filename
theMail.Send
set theMail=nothing

--------------------------------------------

注意:
theMail.AttachFile 第一个参数为服务器实际路径,第二个参数为邮件中显示的文件名

了解更多请访问:http://www.ndfweb.cn/news-108.html
  NDF俱乐部
  国际域名注册
  建站咨询
合作伙伴:万网 | 新网 | 新网互联 NDF网站建设淘宝店 | 实用工具 | 外貿網站建設 | 联系我们
鲁公网安备 37110202000336号 Sitemap - RSSRSS订阅