当前位置: 移动技术网 > IT编程>开发语言>Asp > asp+JMAIL实现发送邮件

asp+JMAIL实现发送邮件

2017年12月08日  | 移动技术网IT编程  | 我要评论

本文利用asp和jmail实现了发送邮件,大家是不是很好奇这到底是怎么实现的呐,和小编一起一探究竟吧!

global.asa文件
什么是global.asa 文件?它其实是一个可选文件,程序编写者可以在该文 件中指定事件脚本,并声明具有会话和应用程序作用域的对象。该文件的内容不是用来给用户显示的,而是用来存储事件信息和由应用程序全局使用的对象。该 文件的名称必须是 global.asa 且必须存放在应用程序的根目录中。每个应用程序只能有一个 global.asa 文件。内容如下:

<script language="vbscript" runat="server">
sub application_onstart '对当前在线人数及访问总量的初始化.
application("online")=0 
application("counter")=0
end sub
sub session_onstart
session.timeout=5 '设置网页到期时间为5分钟
application.lock
application("online")=application("online")+1
application("counter")=application("counter")+1
application.unlock
end sub
sub session_onend
application.lock
application("online")=application("online")-1
application.unlock
end sub
</script>

调用页面代码.test.asp

<%
   '增加当前人数限制处理,提示学员,并发送邮件
'参数说明
'subject     : 邮件标题
'mailaddress : 发件服务器的地址,如smtp.163.com
'email       : 收件人邮件地址
'sender      : 发件人姓名
'content     : 邮件内容
'fromer      : 发件人的邮件地址
sub sendaction(subject, email, sender, content)
set jmail = server.createobject("jmail.message")
jmail.charset = "gb2312" ' 邮件字符集,默认为"us-ascii"
jmail.from = strmailuser ' 发送者地址
jmail.fromname = sender' 发送者姓名
jmail.subject =subject
jmail.mailserverusername = strmailuser' 身份验证的用户名
jmail.mailserverpassword = strmailpass ' 身份验证的密码
jmail.priority = 3'发送邮件类型 1为特级   3为普通
jmail.addrecipient(email)
jmail.body = content
jmail.send(strmailaddress)
end sub
dim title,stremail,strmailadress,strsender,strcontent
dim  strmailaddress,strmailpass,strmailuser,jmail
if application("online")>=1 then
'调用此sub的例子
title     = request("title")
strcontent  = "您好,当前在线人数为"&application("online")
strsender = request("name")  '发信人姓名
stremail       = "a375267603@163.com" '收信人邮箱,可以改为 其它的邮箱
strmailaddress = "mail.cdce.cn" '发件服务器地址    例:smtp.163.com(为163服务器地址)
strmailuser = "zenghai@cdce.cn" '发件人用户名
strmailpass = "8888" '发件账户密码
call sendaction (title,stremail,strsender,strcontent)
strshowmessage = "模块名称:verifystudent[超出人数限制]|详细信息: 当前登录考试系统的人数已经超出服务器的限制【" & application ("online") & "】,请您稍后再登录!"
end if
%>

通过本文了解了global.asa文件是什么,以及如何实现邮件发送,希望对大家的学习有所帮助。

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

相关文章:

验证码:
移动技术网