/**/
ASP CDO.Message 发送邮件完整实例 By shawl.qiu
作用:
ASP 无组件发送电子邮件
实现了直接套用式功能, 只需修改少许选项, 即可使用.
说明:
主要操作皆封装在两个函数里, 一个为发送邮件表单(名 fCdoForm), 一个为发送邮件操作(名 fCdoSendMail)
除主收件人以外, 支持 抄送, 密送.
动态选择使用 TEXT/HTML 格式, 或者两者都选
动态输入SMTP 相关信息
支持是否使用 SSL
支持三种验证方法
附注:
暂不支持附件功能, 主要原因为服务端与客户端的限制.
服务端脚本不允许直接读取客户端文件.
目录:
1. 主内容: 两个主函数及完整应用代码
2. 预览:
shawl.qiu
2006-09-11
1. 主内容: 两个主函数及完整应用代码
linenum
<h1 style="text-align:center!important;color:red!important; ">ASP CDO.Message 发送邮件完整实例 By shawl.qiu</h1>
<h2 style="float:right!important;margin:0px;padding:0px; "><a href=" http://blog.csdn.net/btbtd">shawl.qiu</a> code</h2>
<%
dim mAction, mFrom, mTo, mCC, mBcc, mSubject, mBody
dim mSmtp, mPort, mTimeout, mSsl, mUser, mPwd
mAction="?id=cdo"
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="不告诉你"
dim qId:qId=request.queryString("id")
call fCdoSendMail(qId,request.form)
if qId<>"cdo" then _
call fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
function fCdoSendMail(rQs, rForm)
'''''''''''''''''''''''''''''''''''''''''''''''''''
' ASP CDO.Message 发送邮件完整实例 By shawl.qiu
' CDO 发送邮件操作函数 fCdoSendMail
'''''''''''''''''''''''
' 参数说明:
''''''''''''''
' rQs = request.queryString(id)
' rForm = request.Form 集合
'''''''''''''''''''''''
' sample call:
''''''''''''''
' call fCdoSendMail(qId,request.form)
'''''''''''''''''''''''''''''''''''''''''''''''''''
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 else response.write "邮件已发送"
end with 'shawl.qiu code'
set cdo=nothing
end function
function fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
if mAction="" then exit function
'''''''''''''''''''''''''''''''''''''''''''''''''''
' ASP CDO.Message 发送邮件完整实例 By shawl.qiu
' CDO 发送邮件表单函数 fCdoForm
'''''''''''''''''''''''
' 参数说明: (除 mAction 外, 其余参数值不是必须)
''''''''''''''
' mAction= 表单提交 URL, 如: ?id=cdo
' mFrom= 发件人 Email
' mTo= 收件人 Email
' mCc= 收件人 Email
' mBcc= 收件人 Email
' mSubject= 邮件标题
' mBody= 邮件内容
' mSmtp= SMTP 服务器地址, 如: smtp.21cn.com
' mPort= SMTP 端口, 如: 25
' mTimeout= 超时限制, 如: 60(单位为秒)
' mUser= 用户名
' mPwd= 密码
'''''''''''''''''''''''
' sample call:
''''''''''''''
' dim mAction, mFrom, mTo, mCC, mBcc, mSubject, mBody
' dim mSmtp, mPort, mTimeout, mSsl, mUser, mPwd
' mAction="?id=cdo"
' 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="yourPassword"
' call fCdoForm(mAction,mFrom, mTo, mCc, mBcc, mSubject, mBody, mSmtp, mPort, mTimeout, mUser, mPwd)
'''''''''''''''''''''''''''''''''''''''''''''''''''
%>
<form action="<% response.write mAction %>" method="post" name="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" />
</form><!-- shawl.qiu code -->
<% end function %><br />
<a href="?">back</a>
2. 预览:
ASP 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