当前位置: 移动技术网 > IT编程>开发语言>Asp > asp空间判断jmail组件是否安装或支持的代码

asp空间判断jmail组件是否安装或支持的代码

2017年12月08日  | 移动技术网IT编程  | 我要评论
首先,必须有错误继续进行的声明on error resume next
然后尝试简历jmail实例:
dim jmail
set jmail=server.createobject("jmail.message")

对实例做出判断,如果组件没有安装成功,则没有创建实例:
if jmail is nothing then
response.write "不支持"
else
response.write "支持"
end if

其他组件同样处理,非常简单了。
最好在global文件中处理,里面使用的时候不用那么麻烦了。
最好的方法把邮件生成放到一个表里,然后再说发送的事情。

复制代码 代码如下:

function isobjinstalled(strclassstring)
on error resume next
isobjinstalled = false
err = 0
dim xtestobj
set xtestobj = server.createobject(strclassstring)
if 0 = err then isobjinstalled = true
set xtestobj = nothing
err = 0
end function

判断代码:
if isobjinstalled("jmail.message")=true then{
if isobjinstalled("jmail.message") =true then
sendstat = jmail("***@jb51.net","来自网上的客户留言","<html><head><meta http-equiv=""content-type"" content=""text/html; charset=gb2312""><title>网站用户留言</title></head><body>留言人:"&txtname&"<br>性别:"&xingbie&"<br>咨询网站:"&txtweb&"<br>联系方式:"&txttel&"<br>留言内容:"&content&"<br>ip地址:"&ipaddress&"<br>留言时间:"&now()&"<br><br>本邮件由系统自动发送,无须回复<!--移动技术网www.jb51.net--><br><br></body></html>","gb2312","text/html")
end if
}

jmail发信函数
复制代码 代码如下:

' ============================================
' jmail发送邮件
' ============================================
function jmail(mailto,mailtopic,mailbody,mailcharset,mailcontenttype)

'入口参数:
'    mailto 收件人email地址
'    mailtopic 邮件主题
'    mailbody 邮件正文(内容)
'    mailcharset 邮件字符集,例如gb2312或us-ascii
'    mailcontenttype 邮件正文格式,例如text/plain或text/html
'返回值:
'    字符串,发送成功后返回ok,不成功返回错误信息
'使用方法:
'    1)设置好常量,即以const开头的变量
'    2)使用类似如下代码发信
'dim sendstat
'sendstat = jmail("aa@163.com","测试jmail","这是一封<br/>测试信!","gb2312","text/html")
'response.write sendstat

'***************根据需要设置常量开始*****************
dim constfromnamecn,constfromnameen,constfrom,constmaildomain,constmailserverusername,constmailserverpassword

constfromnamecn = "彩票网"'发信人中文姓名(发中文邮件的时候使用),例如‘张三'
constfromnameen = "bc5"'发信人英文姓名(发英文邮件的时候使用),例如‘zhangsan'
constfrom = "jb51@163.com"'发信人邮件地址,例如‘zhangsan@163.com'
constmaildomain = "smtp.163.com"'smtp服务器地址,例如smtp.163.com
constmailserverusername = "jb51@163.com"'smtp服务器的信箱登陆名,例如‘zhangsan'。注意要与发信人邮件地址一致!
constmailserverpassword = "www.jb51.net"'smtp服务器的信箱登陆密码
'***************根据需要设置常量结束*****************
'-----------------------------以下内容无需改动------------------------------
on error resume next
dim myjmail
set myjmail = server.createobject("jmail.message")
myjmail.logging = false'记录日志
myjmail.isoencodeheaders = false'邮件头不使用iso-8859-1编码
myjmail.contenttransferencoding = "base64"'邮件编码设为base64
myjmail.addheader "priority","3"'添加邮件头,不要改动!
myjmail.addheader "msmail-priority","normal"'添加邮件头,不要改动!
myjmail.addheader "mailer","microsoft outlook express 6.00.2800.1437"'添加邮件头,不要改动!
myjmail.addheader "mimeole","produced by microsoft mimeole v6.00.2800.1441"'添加邮件头,不要改动!
myjmail.charset = mailcharset
myjmail.contenttype = mailcontenttype

if ucase(mailcharset) = "gb2312" then
myjmail.fromname = constfromnamecn
else
myjmail.fromname = constfromnameen
end if

myjmail.from = constfrom
myjmail.subject = mailtopic
myjmail.body = mailbody
myjmail.addrecipient mailto
myjmail.maildomain = constmaildomain
myjmail.mailserverusername = constmailserverusername
myjmail.mailserverpassword = constmailserverpassword
myjmail.send constmaildomain
myjmail.close
set myjmail=nothing

if err then
jmail=err.description
err.clear
else
jmail="ok"
end if

on error goto 0
end function

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网