[轉]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 = "[email protected]"
objMail.To = "[email protected]"
objMail.Subject = "TEST1"
objMail.Send
Set objMail = Nothing

'普通邮件
'有主体
Set objMail = Server.CreateObject("CDONTS.NEWMAIL")
objMail.From = "[email protected]"
objMail.To = "[email protected]"
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 = "[email protected]"
objMail.To = "[email protected];[email protected]"
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 = "[email protected]"
objMail.To = "[email protected]"
objMail.Cc = "[email protected];[email protected]"
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 = "[email protected]"
objMail.To = "[email protected]"
objMail.Cc = "[email protected]"
objMail.Bcc = "[email protected];[email protected]"
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 = "[email protected]"
objMail.To = "[email protected]"
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 = "[email protected]"
objMail.To = "[email protected]"
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
'[email protected] 抄送
'[email protected]密送
'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 = "[email protected]"

'收件人
myMail.To = "[email protected]"

'密件抄送
myMail.Bcc = "[email protected]"

'抄送
myMail.Cc = "[email protected]"

'邮件的重要性
' 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
  [email protected]   "抄送
  [email protected]  "密送
  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

你可能感兴趣的:(mail)