当前位置: 移动技术网 > IT编程>开发语言>Asp > ASP中实现定时发送邮件的代码分享

ASP中实现定时发送邮件的代码分享

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

现在的这个项目需要用asp做定时邮件发送,好多人都说asp没有这样的功能。

其实我在以前的一篇文章已经做过详细的解释了,不过那个是定时任务,基本思路是一样的。

参考:asp中实现执行定时任务的方法

这里我们使用jmail组件的方式来做,邮件的内容为单个网页,可以自由定制。

下面我们看看定时邮件发送的代码:

复制代码 代码如下:

function gethttppage(url)
    dim objxml
    set objxml=createobject("msxml2.serverxmlhttp.3.0")  '调用xmlhttp组件,测试空间是否支持xmlhttp
    objxml.open "get",url,false 'false表示以同步的方式获取网页代码,了解什么是同步?什么是异步?
    objxml.send() '发送
    gethttppage=bbytestobstr(objxml.responsebody)'返回信息,同时用函数定义编码
    set objxml=nothing'关闭
end function
 
 
function bbytestobstr(body)
    dim objstream
    set objstream = createobject("adodb.stream") '//调用adodb.stream组件
    objstream.type = 1
    objstream.mode =3
    objstream.open
    objstream.write body
    objstream.position = 0
    objstream.type = 2
    objstream.charset = "gb2312"
'转换原来默认的utf-8编码转换成gb2312编码,否则直接用xmlhttp调用有中文字符的网页得到的将是乱码
    bbytestobstr = objstream.readtext
    objstream.close
    set objstream = nothing
end function
 
 
 
sub sendaction(subject,mailaddress,tomail,sender,content,fromemail,fromer,username,password)
    set ojmail=createobject("jmail.message")
    ojmail.logging=false
    ojmail.silent=true
    ojmail.priority = 3
    ojmail.fromname=fromer
    ojmail.from= fromemail
    ojmail.charset="gb2312"
    ojmail.mailserverusername = username
    ojmail.mailserverpassword = password
    ojmail.contenttransferencoding = "base64"
    ojmail.htmlbody = content '邮件内容
    ojmail.body =content'"我们的邮件采用了html格式,但是您的邮件查看软件可能不支持"
    ojmail.addrecipient tomail '收件人地址
    ojmail.subject = subject '标题
    ojmail.send(mailaddress)
end sub
 
 
 
 
dim subject,mailaddress,toemail,sender,fromemail,fromer,password,ojmail,usernames,tomail
dim username,useremail
dim pass,content
dim mailname,mailpass,mailform,mailsmtp
mailname="xxx" 'smtp邮箱的账号
mailpass="xxx" 'smtp邮箱的密码
mailform="xxx" 'smtp邮箱的署名
mailsmtp="xxx" 'smtp邮箱的smtp
mailaddress=mailsmtp ': 发件服务器的地址,如smtp.163.com
sender=title'      : 发件人姓名
content=content'     : 邮件内容
fromemail=mailname'   : 发件人邮件地址
fromer=title      ': 发件人姓名
username=mailform'    : 发件邮件帐号
password=mailpass'    : 发件邮件密码
 
 
'需要指定的内容
content=gethttppage("//www.jb51.net/")
subject="标题"     ': 邮件标题
tomail="xxx"     ': 收件人邮件地址
call sendaction(subject,mailaddress,tomail,sender,content,fromemail,fromer,username,password)

将这个文件设置为xxx.vbs以后放到数据库定时执行就可以了。

如果有什么不懂的可以直接问mk。

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

相关文章:

验证码:
移动技术网