JMAIL使用

1.首先要注册JMAIL组件,可以到JMAIL官方网站(www.dimac.net)下载,并安装!

2.


<%   
  
set   Jmail=server.CreateObject("jmail.message")     
          Jmail.MailServerPassWord   
="XXXXXXX"                 '发信授权邮件密码   
          Jmail.MailServerUserName   ="XXXXXXX@163.com"   '发信授权邮件名称  
          Jmail.silent = true    '屏蔽例外错误,返回FALSE跟TRUE两值j
          Jmail.logging = true   '启用邮件日志 
          Jmail.ContentType   =   "text/html"               '(是否支持html,如不要就去掉此行)   
          Jmail.Charset="gb2312"                                 '使用字符集,不用改的   
          Jmail.AddRecipient   "291099657@qq.com"         '收件人邮箱  
                                                           'jmail.addrecipient "somebody@somewhere.com"  '这个地址是真正要发送的地址这样就可以绕开smtp验证了 
   
          Jmail.Body
=   "您好!我是XX"                               '邮件正文   
          Jmail.From="XXX@163.com"             '发件人邮箱   
          '这个最怪了,如果用一个随便的字符有时就不行。不知怎么回事。     
          Jmail.Priority  = 1      '邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值
          Jmail.ReturnReceipt = True   
          Jmail.Subject
=".NET钉子户"                               '邮件标题   
          Jmail.Send   "smtp.163.com",false               '邮件发送服务器   
    
    
if not Jmail.Send(smtpServer) then
     mailError 
= "<pre>" & Jmail.log & "</pre>"
     response.Write mailError
    end 
if
  
set   Jmail   =   nothing  
  response.Write
"<script>alert('发送结束');history.go(-1);</script>"    
  
%>   

 

3.注:可以自己发给自己,即一个邮箱既可以做发件箱,也可作收件箱

4.提取表单中的数据,再发送到邮箱


<%@LANGUAGE="VBSCRIPT"   CODEPAGE="CP_ACP"%>   
  
<%   
      xqname
=request.Form("xqName")   
      who
=request.Form("who")   
      phone
=request.Form("phone")   
      myTime
=request.Form("mytime")   
      email
=request.Form("email")   
        
        
  senderEmail
="idc@ruyi.com"   '发送人邮箱   
    
  subject
="联通宽带在线申请"   '标题   
    
  body
="<html><table><tr><td>"   
  body
=body&"联通宽带在线申请!<br>"   
  body
=body&"所在小区:"&   xqname   &   "<br>"   
  body
=body&"联系人:"&   who   &   "<br>"   
  body
=body&"联系电话:"&   phone   &   "<br>"   
  body
=body&"预约安装时间:"&   myTime   &   "<br>"   
  body
=body&"电子邮箱:"&   email   &   "<br>"   
  body
=body&"<br>"   
  body
=body&"</td></tr></table></html>"   
  
'   Create   the   JMail   message   Object   
  set   msg   =   Server.CreateOBject("JMail.Message")   
    
  msg.Charset   
=   "GB2312"   '邮件的文字编码为国标   
  msg.ContentType   =   "text/html"   
  
'   Set   logging   to   true   to   ease   any   potential   debugging   
  '   And   set   silent   to   true   as   we   wish   to   handle   our   errors   ourself   
  msg.MailServerUserName   =   用户名   
  msg.MailServerPassword   
=   密码   
  msg.Logging   
=   true   
  msg.silent   
=   true   
    
  
'   Enter   the   sender   data   
  msg.From   =   senderEmail   
  msg.FromName   
=   "山东联通"   
    
  
'   Note   that   as   addRecipient   is   method   and   not   
    
  msg.AddRecipient   
"asp@i-smile.net"   '   收件人地址   
  'msg.AddRecipientBCC   "pub@ruyi.com"   
    
  
'   The   subject   of   the   message   
  msg.Subject   =   subject   
    
  
'   And   the   body   
  msg.body   =   body   
  
'   Now   send   the   message,   using   the   indicated   mailserver   
  if   not   msg.Send("smtp.ruyi.com")   then   
          Response.write   
"<pre>"   &   msg.log   &   "</pre>"   
  
'response.Write(msg.ErrorSource)   
  end   if   
  msg.close   
  
set   msg=nothing   
  response.Redirect(
"sendok.htm")   
  
%>   
  

 

5..邮件接收系统。这个例子的执行过程,首先是从存放邮件的服务器上取出邮件,然后把它同附件一起显示在WEB也面上。


<% @LANGUAGE=VBSCRIPT %>
<% 
Set pJmail 
= Server.CreateObject( "JMail.POP3" )
pJmail.Connect 
"username""password""mail.mydomain.com"
Response.Write( 
"你有 " & pJmail.count & " 封新邮件<br><br>" )
if pJmail.count > 0 then
Set msg 
= pJmail.Messages.item(1
ReTo 
= ""
ReCC 
= ""
Set Recipients 
= msg.Recipients
separator 
= ""
For i 
= 0 To Recipients.Count - 1
If i 
= Recipients.Count - 1 Then
separator 
= ""
End If
Set re 
= Recipients.item(i)
If re.ReType 
= 0 Then
ReTo 
= ReTo & re.Name & "&nbsp;(" & re.EMail & ")" & separator
else
ReCC 
= ReTo & re.Name & "&nbsp;(" & re.EMail & ")" & separator
End If
Next
Function getAttachments()
Set Attachments 
= msg.Attachments
separator 
= ""
For i 
= 0 To Attachments.Count - 1
If i 
= Attachments.Count - 1 Then
separator 
= ""
End If
Set at 
= Attachments(i)
at.SaveToFile( 
"c:/fujian/" & at.Name )
getAttachments 
= getAttachments & "<a href=""/fujian/" &_
at.Name 
&""">" & at.Name & "(" & at.Size & " bytes)" &_
"</a>" & separator
Next
End Function

%>
<html>
<body>
<TABLE>
<tr>
<td>主题</td>
<td><%= msg.Subject %></td>
</tr>
<tr>
<td>发件人</td>
<td><%= msg.FromName %></td>
</tr>
<tr>
<td>收件人</td>
<td><%= ReTO %></td>
</tr>
<tr>
<td>抄送人</td>
<td><%= ReCC %></td>
</tr>
<tr>
<td>附件</td>
<td><%= getAttachments %></td>
</tr>
<tr>
<td>正文</td>
<td><pre><%= msg.Body %></pre></td>
</tr>
</TABLE>
</body>
</html>
<%
end 
if
pJmail.Disconnect ‘断开POP3连接
%>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值