呵呵,以前经常有朋友要我帮他们写一个用服务器在后台发送邮件的程序,嫌麻烦,就在我自己的服务器上写了一段代码,以后别人要用服务器来发送邮件时,只需要在自己的程序中简单的写一行引用代码就ok了!
有个前提:必须先在你自己的服务器上安装一个邮件发送组件,我这儿用的是jmail,其它组件,可查看相应的函数说明修改一下我的程序即可.
程序语言: asp(vbscript)
我的服务器地址:http://211.23.12.12 (为保密起见,此地址为杜撰)
服务器端程序sendmail.asp代码如下:
————————————————-
<font size=2 color=green>xxx应用程序服务提供商 自动邮件发送系统</font>
<hr height=1>
<br><br>
<%
邮件发送服务器信息
dim smtpserver,username,password
smtpserver="192.168.10.136" //smtp服务器地址
username="myusername" //服务器认证用户名
password="mypassword" //服务器认证密码
判断使用此功能的用户
dim canok,url
canok=0
url=request.servervariables("http_referer")
该表达式表示用户http://www.liangdie.com被允许调用此功能,检测调用此功能页面是否为http://www.liangdie.com
if mid(url,1,len("http://www.liangdie.com"))="http://www.liangdie.com" then
canok=1
end if
该表达式表示用户http://www.jscy.cn被允许调用此功能,检测调用此功能页面是否为http://www.jscy.cn
if mid(url,1,len("http://www.jscy.cn"))="http://www.jscy.cn" then
canok=1
end if
注意:如需加入其它授权用户,只需依照上面的语法,加入相应的代码即可
开始发送邮件
if canok=1 then
set msg = server.createobject( "jmail.message" )
msg.logging = true 日志记录
msg.silent = true 错误打开
msg.from = request("email")
msg.fromname = request("name")
msg.addrecipient request("recieve"),""
msg.mailserverusername = username 输入smtp服务器验证登陆名 (邮局中任何一个用户的email地址)
msg.mailserverpassword = password 输入smtp服务器验证密码 (用户email帐号对应的密码)
msg.priority = 1 邮件的紧急程序,1 为最快,5 为最慢, 3 为默认值
msg.subject = request("subject")
msg.body=request("body")
if not msg.send(smtpserver) then
response.write "错误信息:<br>"
response.write "<pre>" & msg.log & "</pre>"
else
response.write "<meta http-equiv=refresh content=3;url=" & url & ">"
response.write "<p align=center><font size=2 color=black>邮件发送成功!3秒钟后自动返回!</font></p>"
end if
else
response.write "<p align=center><font size=2 color=red>非法用户或未授权用户!</font></p>"
response.end
end if
%>
<hr height=1>
————————————————-
调用处http://www.jscy.cn/feedback.htm代码如下:
————————————————-
<form name="form" method="get" action="http://211.23.12.12/sendmail.asp">
<input type=text name=email value="customer@liangdie.com">
<input type=text name=name value="customer@liangdie.com">
<input type=text name=body value="">
<input type=text name=subject value="">
<input type="submit" name="submit" value="提 交" onclick="sendmsg.style.visibility=visible">
<input type="reset" name="submit2" value="清 除">
<p id=sendmsg align=center style="visibility:hidden"><font color=red>邮件正在发送,请稍侯……</font></p>
</form>
————————————————-
注意:在发送前须先检查email变量是否为email格式,否则发送程序会报错.在大多数情况下,客户发送的表单信息可能会很多,可通过脚本将这些表单信息全组合到body变量中,再提交给服务器发送.
呵呵,其实当初写完这个程序,觉的有点类似于web service的初级概念了,当然,如果纯粹从技术角度出发来看这段程序,与web service的技术实现相差的太远了,但使用起来的方式却有点类似了.
