ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu

ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu


摘要:
前两天也写了一篇相关的文章: ASP CDO.Message 发送邮件完整实例 By shawl.qiu
URL:    http://blog.csdn.net/btbtd/archive/2006/09/11/1210050.aspx

不过我发觉还没写过类, 所以呗, 就试了一下, 其实 ASP 的类挻简单的, 喏, 这不今天看相关信息, 现在就出产文章啦 :)

其实吧, 我觉得 ASP类 和普通函数过程可以比喻为:
类是一个箱子, 函数和过程是箱子里的东西. 
使用类可以简化调用函数的操作, 用 get 实现.
用 let 在类外边给参数赋值, 至于 set, 目前还没用过. 

类相关信息:
类名: cCdoMessage
作用: 使用 ASP 的内建组件 CDO.Message 发送电子邮件

附注: 不支持附件.

目录:
1. cCdoMessage 类内容
2. 调用 cCdoMessage 类
3. 预览

shawl.qiu
2006-09-12
http://blog.csdn.net/btbtd

1. cCdoMessage 类内容
  1. linenum
  2. <%    class cCdoMessage
  3.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  4.     ' ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu
  5.     '''''''''''''''''''''''''
  6.     ' sample call:
  7.     '''''''''''
  8.     '    dim objCdo
  9.     '    set objCdo= new cCdoMessage
  10.     '        with objCdo
  11.     '            .header ' 头部信息, 非必须
  12.     '            .rQs=request.queryString("id") '查询 ID, 必选项
  13.     '            set .rForm=request.form '提交表单集合, 必选项
  14.     '                .pgCdoSendMail
  15.     '            set .rForm=nothing
  16.     '            
  17.     '            .mAction="?id=cdo" '提交表单 URL, 必选项
  18.     '            ''''''''''''''''''''''''''''''''''''''''''''
  19.     '            ' start 表单域默认内容, 非必须
  20.     '            .mFrom="shawlqiu@21cn.com"
  21.     '            .mTo="shawl.qiu@gmail.com,btbtd@msn.com"
  22.     '            .mCc="btbtd@yahoo.com.cn"
  23.     '            .mBcc="shawl.qiu+2@gmail.com"
  24.     '            .mSubject="mail subject"
  25.     '            .mBody="test mail body"&chr(13)&"中文"&chr(13)&"<h2>html format</h2>"
  26.     '            .mSmtp="smtp.21cn.com"
  27.     '            .mPort=25
  28.     '            .mTimeout=60
  29.     '            .mUser="shawlqiu"
  30.     '            .mPwd="不告诉你"
  31.     '            ' end 表单域默认内容, 非必须
  32.     '            ''''''''''''''''''''''''''''''''''''''''''''
  33.     '            .pgCdoform ' 发送邮件表单, 必选项
  34.     '            
  35.     '            .info ' 作者信息, 非必须
  36.     '        end with
  37.     '    set objCdo=nothing
  38.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  39.         public sub info()
  40.             response.write "<br/>Subject: ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu<br/>"
  41.             response.write "Author: shawl.qiu<br/>"
  42.             response.write "Version: 1.0<br/>"
  43.             response.write "Date: 2006-09-12<br/>"
  44.             response.write "Blog:   http://blog.csdn.net/btbtd<br/>"
  45.             response.write "E-Mail: shawl.qiu@gmail.com<br/>"
  46.         end sub
  47.     
  48.         public rQs, rForm
  49.         public mAction, mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd
  50.     
  51.         public function header()
  52.             response.write "<h1 style=""text-align:center!important;color:red!important; "">ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu</h1>"
  53.             response.write "<h2 style=""float:right!important;margin:0px;padding:0px; ""><a href="" http://blog.csdn.net/btbtd"">shawl.qiu</a> code</h2>"
  54.         end function
  55.         
  56.         public property get pgCdoform
  57.             pgCdoform=fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
  58.         end property
  59.         
  60.         public property get pgCdoSendMail
  61.             pgCdoSendMail=fCdoSendMail(rQs,rForm)
  62.         end property
  63.  
  64.         private property get goBack
  65.             goBack=fPmt("邮件已发送, 3 秒后返回.",3,request.ServerVariables("HTTP_REFERER"))
  66.         end property
  67.         
  68.         private property get goBackErr
  69.             goBackErr="<a href="""&request.ServerVariables("HTTP_REFERER")&""" style=""text-align:center!important; display:table; width:100%;"">返回</a>"
  70.         end property
  71.  
  72.         private    function fPmt(promptWord,second,url)
  73.             response.write "<div class=""absltMid""><meta http-equiv=""refresh"" content="""
  74.             response.write second
  75.             response.write ";URL="
  76.             response.write url
  77.             response.write """>"
  78.             response.write promptWord
  79.             response.write "</div>"
  80.         end function 
  81.  
  82.         private function fCdoSendMail(rQs,rForm)
  83.             if rQs="" or rQs<>"cdo" then exit function
  84.             if isObject(rForm)=false then exit function
  85.             dim temp
  86.             for each temp in rForm
  87.                 select case temp
  88.                     case "mTextBody"
  89.                     case "mHtmlBody"
  90.                     case "mFile"
  91.                     case "mSsl"
  92.                     case else
  93.                         execute "dim "&temp&":"&temp&"=request.form(temp)"
  94.                 end select
  95.             next
  96.             dim mSsl, mTextBody, mHtmlBody
  97.                 mSsl=request.form("mSsl")
  98.                 mTextBody=request.form("mTextBody")
  99.                 mHtmlBody=request.form("mHtmlBody")
  100.                 mBody="<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"" />"&chr(13)&mBody
  101.                 
  102.                 if mSsl="" then mSsl=false else mSsl=true
  103.             dim cdo 
  104.             set cdo=createObject("cdo.message")
  105.                 'configuration information for the remote SMTP Server
  106.                 with cdo.configuration.fields
  107.                     .Item(" http://schemas.microsoft.com/cdo/configuration/sendusing") = mSend
  108.                     .item(" http://schemas.microsoft.com/cdo/configuration/smtpserver")= mSmtp 'SMTP 服务器地址
  109.                     .item(" http://schemas.microsoft.com/cdo/configuration/smtpserverport")= mPort '端口 25
  110.                     .item(" http://schemas.microsoft.com/cdo/configuration/sendusername")= mUser '用户名
  111.                     .item(" http://schemas.microsoft.com/cdo/configuration/sendpassword")= mPwd '用户密码
  112.                     .item(" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")= mAuth 'NONE, Basic (Base64 encoded), NTLM
  113.                     .item(" http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")= mTimeout '超时设置, 以秒为单位
  114.                     .Item(" http://schemas.microsoft.com/cdo/configuration/smtpusessl") = mSsl '是否使用套接字 true/false 
  115.                     .Update
  116.                 end with
  117.                 with cdo
  118.                     .from=mFrom
  119.                     .to=mTo
  120.                     if mCc<>"" then .cc=mCc
  121.                     if mBcc<>"" then .bcc=mBcc
  122.                     .subject=mSubject
  123.                     if mTextBody<>"" then .textbody=mBody
  124.                     if mHtmlBody<>"" then .htmlbody=mBody
  125.                     
  126.                     'if len(mFile)>0 then .Addattachment mFile
  127.                     '// CDO 发附件规则: 当前目录的文件可用变量, 不是当前的目录不能用变量
  128.                     On Error Resume Next
  129.                     .send
  130.                     if err.number<>0 then response.write "邮件发送失败, 错误编号: "&_
  131.                     err.number&"<br/>错误描述: "&err.description&goBackErr else goBack
  132.                 end with 'shawl.qiu code'
  133.             set cdo=nothing
  134.         end function
  135.  
  136.         private function fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
  137.         if mAction="" then exit function %>
  138.             <form action="<% response.write mAction %>" method="post" name="mCdo" id="mCdo">
  139.               <p>From: 
  140.                 <input name="mFrom" type="text" value="<% response.write mFrom %>" size="50%"/><br />
  141.                 To: <input name="mTo" type="text" value="<% response.write mTo %>" size="50%" /> 
  142.                 <br />
  143.                 Cc: <input name="mCc" type="text" value="<% response.write mCc %>" size="50%" /><br />
  144.                 Bcc: <input name="mBcc" type="text" id="mBcc" value="<% response.write mBcc %>" size="50%" /> <br />
  145.                 Subject: <input name="mSubject" type="text" value="<% response.write mSubject %>" size="50%" /> <br />
  146.                 Email Format: 
  147.                 text: <input type="checkbox" name="mTextBody" value="yes" checked="checked" /> 
  148.                 html: <input type="checkbox" name="mHtmlBody" value="yes" /><br />
  149.                 Text:<br /> <textarea name="mBody" cols="77" rows="10"><% response.write mBody %></textarea> <br /> 
  150.                 Remote SMTP: <input name="mSmtp" type="text" value="<% response.write mSmtp %>" />
  151.                 Port: <input name="mPort" type="text" value="<% response.write mPort %>" size="5" />
  152.                 Timeout: <input name="mTimeout" type="text" value="<% response.write mTimeout %>" size="5" />
  153.                 Sec SSL: <input type="checkbox" name="mSsl" value="ture" /> <br />
  154.                 Username: <input name="mUser" type="text" value="<% response.write mUser %>" /> <br />
  155.                 Password: <input name="mPwd" type="password" value="<% response.write mPwd %>" />  <br />
  156.                 SMTP验证选项: 
  157.                 <select name="mAuth">
  158.                     <option value="0">匿名验证</option>
  159.                     <option value="1" selected="selected">普通验证</option>
  160.                     <option value="2">NTLM 验证</option>
  161.                 </select> 
  162.                  邮件发送选项: 
  163.                  <select name="mSend">
  164.                     <option value="1">Send Using Pickup</option>
  165.                     <option value="2" selected="selected">Send Using Port</option>
  166.                  </select>
  167.                  <br />
  168.                 <input type="submit" value="Submit" />   <input type="reset" value="Reset" />
  169.             </p>
  170.             </form><!-- shawl.qiu code -->
  171.     <%     end function 
  172.     end class %>

2. 调用 cCdoMessage 类
  1. linenum
  2. <%
  3.     dim objCdo
  4.     set objCdo= new cCdoMessage
  5.         with objCdo
  6.             .header ' 头部信息, 非必须
  7.             .rQs=request.queryString("id") '查询 ID, 必选项
  8.             set .rForm=request.form '提交表单集合, 必选项
  9.                 .pgCdoSendMail
  10.             set .rForm=nothing
  11.             
  12.             .mAction="?id=cdo" '提交表单 URL, 必选项
  13.             ''''''''''''''''''''''''''''''''''''''''''''
  14.             ' start 表单域默认内容, 非必须
  15.             .mFrom="shawlqiu@21cn.com"
  16.             .mTo="shawl.qiu@gmail.com,btbtd@msn.com"
  17.             .mCc="btbtd@yahoo.com.cn"
  18.             .mBcc="shawl.qiu+2@gmail.com"
  19.             .mSubject="mail subject"
  20.             .mBody="test mail body"&chr(13)&"中文"&chr(13)&"<h2>html format</h2>"
  21.             .mSmtp="smtp.21cn.com"
  22.             .mPort=25
  23.             .mTimeout=60
  24.             .mUser="shawlqiu"
  25.             .mPwd="不告诉你"
  26.             ' end 表单域默认内容, 非必须
  27.             ''''''''''''''''''''''''''''''''''''''''''''
  28.             .pgCdoform ' 发送邮件表单, 必选项
  29.             
  30.             .info ' 作者信息, 非必须
  31.         end with
  32.     set objCdo=nothing
  33. %>

3. 预览

ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu

shawl.qiu code

From:
To:
Cc:
Bcc:
Subject:
Email Format: text: html:
Text:

Remote SMTP: Port: Timeout: Sec SSL:
Username:
Password:
SMTP验证选项: 邮件发送选项:


Subject: ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu
Author: shawl.qiu
Version: 1.0
Date: 2006-09-12
Blog: http://blog.csdn.net/btbtd
E-Mail: shawl.qiu@gmail.com


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值