ASP在线群发源码!Jmail的需先安装jmail组件!
时间:2010-08-26 来源:龙圆
在线发送邮件
    1、jmail发送邮件
    要做在线发邮件首先要该服务器支持jamil组件(现在的空间商基本上都支持),如果在自己机子上测试的
    时候到网上去找个jmail安装一个就行了,记住本程序只适用于4.2以后的版本!
    <%
    domain = "smtp.163.com"
    ename=request.form("name")
    email=request.form("email")
    subject=request.form("subject")
    message=request.form("message")
  
    dim jmail
    set jmail=server.createobject("Jmail.message")
    jmail.silent=true
    jmail.charset="gb2312"
    jmail.fromname=ename '这里是发件人名称,可以从数据库或表单中取值
    jmail.from=email '这里是发件人邮箱,可以从数据库或表单中取值,但格式一定要正确 <br>
    jmail.subject=subject '该值可以从数据库或表单中取值
    jmail.HTMLBody = Message
  
    jmail.AddHeader "Originating-IP", Request.ServerVariables("[email protected]    ")
    jmail.AddRecipient"mailto:[email protected]%22,%22service"    '"收件人邮箱地址","收件人姓名"
    jmail.mailserverusername="smtp服务器登录用户名" '邮件发送服务器登录名称
    jmail.mailserverpassword="smtp服务器登录密码" '邮件发送服务器登录密码
    jmail.maildomain="邮件服务器域名" '邮件发送服务器域名
    sendok=jmail.send("domain") 'smtp服务器名称
    if sendok then
    response.write "恭喜您,邮件发送成功"
    else
    response.write "对不起,邮件发送失败,可能由于服务器登录设置配置不当造成或填写的信息有误,请
    确认正确后再进行发送!"
    end if %>
    上面就是利用jmail发送邮件的主要代码
    下面还有一个html页面就是用来填写发送信息的
    <html>
    <head>
    <title>小妖——在线发送邮件</title>
    <meta http-equiv="content-type=" content="text/html; charset=gb2312">
    </head>
    <body>
    <form method="post" action="">
    发件人名称:<input type="text" name="fname"><br>
    发件人邮箱:<input type="text" name="femail"><br>
    收件人名称:<input type="text" name="tname"><br>
    收件人邮箱:<input type="text" name="temail"><br>
    邮件标题:<input type="text" name="title"><br>
    邮件内容:<textarea rows="9" cols="40" name="content"></textarea><br>
    <div align="center"><input type="submit" name="submit" value="发送"></div>
    </form>
    </body>
    </html>
    已经全部结束了,上面那个发送邮件的asp代码中的注释部分可以用表单值代替,不过最好写成先把
    值赋给一个变量,如:title=request.form("title"),然后把注释部份用title代替,一但用了变变量赋
    值时就要把jmail.subject=""这对引号去掉了可以直接写成jmail.subject=title就OK了。
    
    2、无组件发送邮件
    自动发送处理代码:
    <%
    Dim MailObject
    Response.Write "正在发送邮件......<BR>"
    Mailto = Request("Mailto")
    Mailfrom = Request("Mailfrom")
    Mailsubject = Request("Mailsubject")
    Mailbody = Request("Mailbody")
    Mailfile = Request("Mailfile")
    
    Set MailObject = Server.CreateObject("CDONTS.NewMail")
    '收信人地址
    MailObject.To = Mailto
    '发信人地址
    MailObject.From = Mailfrom
    '信件标题
    MailObject.Subject = Mailsubject
    '信件内容
    MailObject.Body = Mailbody
    '附件地址
    MailObject.AttachFile Mailfile
    '开始发送邮件
    MailObject.Send
    Set MailObject = Nothing
    Response.Write "邮件发送成功了"
    %>
    
    3、微软自带CDONTS组件发送核心代码:
    <%
    Set cdomail = Server.CreateObject("CDONTS.NewMail") '建立邮件对象
    cdomail.Subject = "Mail Subject" '邮件标题
    cdomail.From = "Sender's Mail" '发件人的地址
    cdomail.To = "Email will from" '收件人的地址
    cdomail.Body = "Mail Body" '邮件的内容
    cdomail.Send '执行发送
    %>
    
    Jmail程序调用:
    <%
    '参数说明
    'Subject : 邮件标题
    'MailAddress : 发件服务器的地址,如smtp.163.com
    'Email : 收件人邮件地址
    'Sender : 发件人姓名
    'Content : 邮件内容
    'Fromer : 发件人的邮件地址
    
    Sub SendAction(subject, mailaddress, email, sender, content, fromer)
    Set jmail = Server.CreateObject("JMAIL.SMTPMail") '创建一个JMAIL对象
    jmail.silent = true 'JMAIL不会抛出例外错误,返回的值为FALSE跟TRUE
    jmail.logging = true '启用使用日志
    jmail.Charset = "GB2312" '邮件文字的代码为简体中文
    jmail.ContentType = "text/html" '邮件的格式为HTML的
    jmail.ServerAddress = mailaddress '发送邮件的服务器
    jmail.AddRecipient Email '邮件的收件人
    jmail.SenderName = sender '邮件发送者的姓名
    jmail.Sender = fromer '邮件发送者的邮件地址
    jmail.Priority = 1 '邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值
    jmail.Subject = subject '邮件的标题
    jmail.Body = content '邮件的内容
    '由于没有用到密抄跟抄送,这里屏蔽掉这两句,如果您有需要的话,可以在这里恢复
    'jmail.AddRecipientBCC Email '密件收件人的地址
    'jmail.AddRecipientCC Email '邮件抄送者的地址
    jmail.Execute() '执行邮件发送
    jmail.Close '关闭邮件对象
    End Sub
    
    '调用此Sub的例子
    Dim strSubject,strEmail,strMailAdress,strSender,strContent,strFromer
    strSubject = "这是一封用JMAIL发送的测试邮件"
    strContent = "JMail组件发送测试成功!"
    strEmail = "[email protected]"
    strFromer = "[email protected]"
    strMailAddress = "mail.ubbcn.com"
    
    Call SendAction (strSubject,strMailaddress,strEmail,strSender,strContent,strFromer)
    
    %>
    jmail.smtpmail的核心代码:
    <%
    Set jmail = Server.CreateObject("JMAIL.SMTPMail") '创建一个JMAIL对象
    jmail.silent = true 'JMAIL不会抛出例外错误,返回的值为FALSE跟TRUE
    jmail.logging = true '启用使用日志
    jmail.Charset = "GB2312" '邮件文字的代码为简体中文
    jmail.ContentType = "text/html" '邮件的格式为HTML的
    jmail.ServerAddress = "Server Address" '发送邮件的服务器
    jmail.AddRecipient Email '邮件的收件人
    jmail.SenderName = "SenderName" '邮件发送者的姓名
    jmail.Sender = "Email Address" '邮件发送者的邮件地址
    jmail.Priority = 1 '邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值
    jmail.Subject = "Mail Subject" '邮件的标题
    jmail.Body = "Mail Body" '邮件的内容
    jmail.AddRecipientBCC Email '密件收件人的地址
    jmail.AddRecipientCC Email '邮件抄送者的地址
    jmail.Execute() '执行邮件发送
    jmail.Close '关闭邮件对象
    %>
    
    w3 Jmail4.3组件核心代码:
    <%
    Set jmail = Server.CreateObject("JMAIL.Message") '建立发送邮件的对象
    jmail.silent = true '屏蔽例外错误,返回FALSE跟TRUE两值j
    mail.logging = true '启用邮件日志
    jmail.Charset = "GB2312" '邮件的文字编码为国标
    jmail.ContentType = "text/html" '邮件的格式为HTML格式
    jmail.AddRecipient Email '邮件收件人的地址
    jmail.From = "Email From for Sender" '发件人的E-MAIL地址
    jmail.MailServerUserName = "UserName of Email" '登录邮件服务器所需的用户名
    jmail.MailServerPassword = "Password of Email" '登录邮件服务器所需的密码
    jmail.Subject = "Mail Subject" '邮件的标题
    jmail.Body = "Mail Body" '邮件的内容
    jmail.Prority = 1 '邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值
    jmail.Send("Server Address") '执行邮件发送(通过邮件服务器地址)
    jmail.Close() '关闭对象
    %>
    
    4、FLASH+ASP发邮件的代码
  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<%
Dim email,topic,mailbody,sendto
ytopic=request.Form("ytopic")
yname=request.Form("yname")
yemail=request.Form("yemail")
yhome=request.Form("yhome")
ycontent=request.Form("ycontent")
mailbody="<div style='font-size:10pt'>"
mailbody=mailbody+"名字:"+yname+"<br>"
mailbody=mailbody+"网址:"+yhome+"<br>"
mailbody=mailbody+"邮件:"+yemail+"<br>"
mailbody=mailbody+"内容:"+ycontent+"<br>"
mailbody=mailbody+"</div>"
topic="[RIACN反馈]"+ytopic
sendto="[email protected]"
call Jmail(topic,mailbody,sendto)
sub Jmail(topic,mailbody,sendto)
on error resume next
dim JMail
Set JMail=Server.CreateObject("JMail.Message")
JMail.Logging = True
JMail.ContentType = "text/html"
JMail.From = "[email protected]"
JMail.Subject = topic
JMail.Body = mailbody
JMail.AddRecipient sendto
JMail.Priority = 3
JMail.Send("mail.domain.com")
Set JMail = nothing
'关闭并清除对象
JMail.Close()
Set JMail = Nothing
if err.number = 0 then
Response.Write("success=1")
end if
end sub
%> 5、Jmail问题集锦
      1、JMAIL的版本是多少?
      JMAIL 是免费的4.0版本
    
      2、JMAIL 需要单独的发信服务器吗?
      JMAIL 需要设置单独的发信服务器
      如:set mail=server.CreateObject("jmail.SMTPMail")
      mail.ServerAddress = "mail.domain.com"
    
      3、为什么使用jmail发信时发信失败?
      最可能的原因是你指定的发信服务器需要发信认证,而你在程序中没有指定发信用户名和密码,具体的编码为:
      set mail=CreateObject("jmail.Message")
      mail.Charset ="gb2312"
      mail.From ="[email protected]"
      mail.AddRecipient "[email protected]"
      mail.MailDomain="mail.hichina.com"
      mail.MailServerUserName = " from @hichina.com"
      mail.MailServerPassWord = "****"
      mail.subject=”test”
      mail.body= “欢迎”
      'On Error Resume Next
      mail.Send("mail.hichina.com")
      mail.close()
      set mail=nothing
    
      4、Jmail 能发送附件吗?
      可以
      mail.AddAttachment (replace(server.MapPath("/test.doc"),"",""))
    
      5、 Jmail 可以发送Html格式的邮件吗?
      可以,具体看使用手册。
    
      6、Jmail组件实例。
      
      (1)发信服务器需要认证(万网邮箱适用)
      <%
      set mail=CreateObject("jmail.Message")
      mail.Charset ="gb2312"
      mail.From ="[email protected]"      '发送人的邮件地址
      mail.AddRecipient "[email protected]"     '接收者的邮件地址
      mail.MailDomain="mx.hichina.com"     '改成可以正常使用的邮件服务器的IP或域名
      mail.MailServerUserName = "[email protected]"    '邮件服务器的邮箱地址
      mail.MailServerPassWord = "*****"     '邮件服务器的邮箱密码
      mail.subject="标题"       '标题
      mail.body= "正文"       '正文
      On Error Resume Next
      mail.Send("mx.hichina.com")      '改成可以正常使用的邮件服务器的IP或域名
      mail.close()
      set mail=nothing
      response.write "发送成功"
      %>
    
      (2)发信服务器不需要认证
      <%
      set mail=server.CreateObject("jmail.SMTPMail")
      mail.Charset="gb2312"
      mail.ServerAddress = "mx.hichina.com"     '改成可以正常使用的邮件服务器的IP或域名
      mail.Sender="[email protected]"       '发送人的邮件地址
      mail.SenderName="test"
      mail.AddRecipient("[email protected]")     '接收者的邮件地址
      mail.Subject ="标题"       '标题
      mail.body="正文"       '正文
      mail.Priority="1"
      'On Error Resume Next
      mail.Execute()
      mail.Close
      Set mail=nothing
      response.write "发送成功"
      %>
    
      7、Jmail发信的实例,模块化随时调用
      一个用jmail发信的过程,及使用方法. 发信时,直接调用这个过程就行了。   
          <%
          dim str,HtmlBody
          HtmlBody="<html><body bgcolor='red' topmargin='40'><p align='center'>I Love 2Yup!</p></html>"
          str=JmailSend( "hello","ILoveYou",true,HtmlBody,"[email protected]",[email protected],
          "hello","smtp.sina.com.cn","hello","Password")    
          if str="Y" then
           response.write("发送成功")
          else
           response.write("发送失败!请重试!")
          end if
          '=================================================
          '函数名:JmailSend
          '作 用:用Jmail发送邮件
          '参 数:Subject 邮件标题
          ' Body 邮件内容
          ' Body 邮件内容
          ' isHtml 是否发送Html格式邮件 (true 是)
          ' HtmlBody Html格式邮件内容
          '    MailTo 收件人Email
          ' From 发件人Email
          ' FromName 发件人姓名
          ' Smtp smtp服务器
          ' Username 邮箱用户名
          ' Password 邮箱密码
          '返回值:JmailSend="N" 发送失败 JmailSend="Y" 发送成功
          '~~~~~~~~~~suercool~~~~~
         
          '=================================================
           function JmailSend(Subject,Body,isHtml,HtmlBody,MailTo,From,FromName,Smtp,Username,Password)
           dim JmailMsg
           set JmailMsg=server.createobject("jmail.message")
           JmailMsg.mailserverusername=Username
           JmailMsg.mailserverpassword=Password
         
           JmailMsg.addrecipient MailTo
           JmailMsg.from=From
           JmailMsg.fromname=FromName
         
           JmailMsg.charset="gb2312"
           JmailMsg.logging=true
           JmailMsg.silent=true
         
           JmailMsg.subject=Subject
           JmailMsg.body=Body
           if isHtml=true then JmailMsg.htmlbody=HtmlBody
         
           if not JmailMsg.send(Smtp) then
           JmailSend="N"
           else
           JmailSend="Y"
           end if
           JmailMsg.close
           set JmailMsg=nothing
          end function
          %>
    










