[轉]CDONTS.NewMail发邮件-详细篇
使用过国外服务器的朋友,特别是使用Godaddy主机的朋友,一定对这个邮件发送组件不会陌生,在这里就给大家带来一篇详细的使用方法:
<%
'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
%>
<%
'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
%>
轉自:http://blog.sina.com.cn/s/blog_5017a4f00100hdau.html
參考:
http://www.wowbox.com.tw/blog/article.asp?id=2277
http://msdn.microsoft.com/en-us/library/ms526367(EXCHG.10).aspx
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。