/**/
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
1. cCdoMessage 类内容
linenum
<% class cCdoMessage
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu
'''''''''''''''''''''''''
' sample call:
'''''''''''
' dim objCdo
' set objCdo= new cCdoMessage
' with objCdo
' .header ' 头部信息, 非必须
' .rQs=request.queryString("id") '查询 ID, 必选项
' set .rForm=request.form '提交表单集合, 必选项
' .pgCdoSendMail
' set .rForm=nothing
'
' .mAction="?id=cdo" '提交表单 URL, 必选项
' ''''''''''''''''''''''''''''''''''''''''''''
' ' start 表单域默认内容, 非必须
' .mFrom="shawlqiu@21cn.com"
' .mTo="shawl.qiu@gmail.com,btbtd@msn.com"
' .mCc="btbtd@yahoo.com.cn"
' .mBcc="shawl.qiu+2@gmail.com"
' .mSubject="mail subject"
' .mBody="test mail body"&chr(13)&"中文"&chr(13)&"<h2>html format</h2>"
' .mSmtp="smtp.21cn.com"
' .mPort=25
' .mTimeout=60
' .mUser="shawlqiu"
' .mPwd="不告诉你"
' ' end 表单域默认内容, 非必须
' ''''''''''''''''''''''''''''''''''''''''''''
' .pgCdoform ' 发送邮件表单, 必选项
'
' .info ' 作者信息, 非必须
' end with
' set objCdo=nothing
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public sub info()
response.write "<br/>Subject: ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu<br/>"
response.write "Author: shawl.qiu<br/>"
response.write "Version: 1.0<br/>"
response.write "Date: 2006-09-12<br/>"
response.write "Blog: http://blog.csdn.net/btbtd<br/>"
response.write "E-Mail: shawl.qiu@gmail.com<br/>"
end sub
public rQs, rForm
public mAction, mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd
public function header()
response.write "<h1 style=""text-align:center!important;color:red!important; "">ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu</h1>"
response.write "<h2 style=""float:right!important;margin:0px;padding:0px; ""><a href="" http://blog.csdn.net/btbtd"">shawl.qiu</a> code</h2>"
end function
public property get pgCdoform
pgCdoform=fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
end property
public property get pgCdoSendMail
pgCdoSendMail=fCdoSendMail(rQs,rForm)
end property
private property get goBack
goBack=fPmt("邮件已发送, 3 秒后返回.",3,request.ServerVariables("HTTP_REFERER"))
end property
private property get goBackErr
goBackErr="<a href="""&request.ServerVariables("HTTP_REFERER")&""" style=""text-align:center!important; display:table; width:100%;"">返回</a>"
end property
private function fPmt(promptWord,second,url)
response.write "<div class=""absltMid""><meta http-equiv=""refresh"" content="""
response.write second
response.write ";URL="
response.write url
response.write """>"
response.write promptWord
response.write "</div>"
end function
private function fCdoSendMail(rQs,rForm)
if rQs="" or rQs<>"cdo" then exit function
if isObject(rForm)=false then exit function
dim temp
for each temp in rForm
select case temp
case "mTextBody"
case "mHtmlBody"
case "mFile"
case "mSsl"
case else
execute "dim "&temp&":"&temp&"=request.form(temp)"
end select
next
dim mSsl, mTextBody, mHtmlBody
mSsl=request.form("mSsl")
mTextBody=request.form("mTextBody")
mHtmlBody=request.form("mHtmlBody")
mBody="<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"" />"&chr(13)&mBody
if mSsl="" then mSsl=false else mSsl=true
dim cdo
set cdo=createObject("cdo.message")
'configuration information for the remote SMTP Server
with cdo.configuration.fields
.Item(" http://schemas.microsoft.com/cdo/configuration/sendusing") = mSend
.item(" http://schemas.microsoft.com/cdo/configuration/smtpserver")= mSmtp 'SMTP 服务器地址
.item(" http://schemas.microsoft.com/cdo/configuration/smtpserverport")= mPort '端口 25
.item(" http://schemas.microsoft.com/cdo/configuration/sendusername")= mUser '用户名
.item(" http://schemas.microsoft.com/cdo/configuration/sendpassword")= mPwd '用户密码
.item(" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")= mAuth 'NONE, Basic (Base64 encoded), NTLM
.item(" http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")= mTimeout '超时设置, 以秒为单位
.Item(" http://schemas.microsoft.com/cdo/configuration/smtpusessl") = mSsl '是否使用套接字 true/false
.Update
end with
with cdo
.from=mFrom
.to=mTo
if mCc<>"" then .cc=mCc
if mBcc<>"" then .bcc=mBcc
.subject=mSubject
if mTextBody<>"" then .textbody=mBody
if mHtmlBody<>"" then .htmlbody=mBody
'if len(mFile)>0 then .Addattachment mFile
'// CDO 发附件规则: 当前目录的文件可用变量, 不是当前的目录不能用变量
On Error Resume Next
.send
if err.number<>0 then response.write "邮件发送失败, 错误编号: "&_
err.number&"<br/>错误描述: "&err.description&goBackErr else goBack
end with 'shawl.qiu code'
set cdo=nothing
end function
private function fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
if mAction="" then exit function %>
<form action="<% response.write mAction %>" method="post" name="mCdo" id="mCdo">
<p>From:
<input name="mFrom" type="text" value="<% response.write mFrom %>" size="50%"/><br />
To: <input name="mTo" type="text" value="<% response.write mTo %>" size="50%" />
<br />
Cc: <input name="mCc" type="text" value="<% response.write mCc %>" size="50%" /><br />
Bcc: <input name="mBcc" type="text" id="mBcc" value="<% response.write mBcc %>" size="50%" /> <br />
Subject: <input name="mSubject" type="text" value="<% response.write mSubject %>" size="50%" /> <br />
Email Format:
text: <input type="checkbox" name="mTextBody" value="yes" checked="checked" />
html: <input type="checkbox" name="mHtmlBody" value="yes" /><br />
Text:<br /> <textarea name="mBody" cols="77" rows="10"><% response.write mBody %></textarea> <br />
Remote SMTP: <input name="mSmtp" type="text" value="<% response.write mSmtp %>" />
Port: <input name="mPort" type="text" value="<% response.write mPort %>" size="5" />
Timeout: <input name="mTimeout" type="text" value="<% response.write mTimeout %>" size="5" />
Sec SSL: <input type="checkbox" name="mSsl" value="ture" /> <br />
Username: <input name="mUser" type="text" value="<% response.write mUser %>" /> <br />
Password: <input name="mPwd" type="password" value="<% response.write mPwd %>" /> <br />
SMTP验证选项:
<select name="mAuth">
<option value="0">匿名验证</option>
<option value="1" selected="selected">普通验证</option>
<option value="2">NTLM 验证</option>
</select>
邮件发送选项:
<select name="mSend">
<option value="1">Send Using Pickup</option>
<option value="2" selected="selected">Send Using Port</option>
</select>
<br />
<input type="submit" value="Submit" /> <input type="reset" value="Reset" />
</p>
</form><!-- shawl.qiu code -->
<% end function
end class %>
2. 调用 cCdoMessage 类
linenum
<%
dim objCdo
set objCdo= new cCdoMessage
with objCdo
.header ' 头部信息, 非必须
.rQs=request.queryString("id") '查询 ID, 必选项
set .rForm=request.form '提交表单集合, 必选项
.pgCdoSendMail
set .rForm=nothing
.mAction="?id=cdo" '提交表单 URL, 必选项
''''''''''''''''''''''''''''''''''''''''''''
' start 表单域默认内容, 非必须
.mFrom="shawlqiu@21cn.com"
.mTo="shawl.qiu@gmail.com,btbtd@msn.com"
.mCc="btbtd@yahoo.com.cn"
.mBcc="shawl.qiu+2@gmail.com"
.mSubject="mail subject"
.mBody="test mail body"&chr(13)&"中文"&chr(13)&"<h2>html format</h2>"
.mSmtp="smtp.21cn.com"
.mPort=25
.mTimeout=60
.mUser="shawlqiu"
.mPwd="不告诉你"
' end 表单域默认内容, 非必须
''''''''''''''''''''''''''''''''''''''''''''
.pgCdoform ' 发送邮件表单, 必选项
.info ' 作者信息, 非必须
end with
set objCdo=nothing
%>
3. 预览
ASP Class(类) 之 使用内建组件 cdo.message 发送邮件 By shawl.qiu
shawl.qiu code
From:
To:
Cc:
Bcc:
Subject:
Email Format: text: html:
Text:
test mail body
中文
<h2>html format</h2>
Remote SMTP: Port: Timeout: Sec SSL:
Username:
Password:
SMTP验证选项:
匿名验证
普通验证
NTLM 验证
邮件发送选项:
Send Using Pickup
Send Using Port
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