呵呵,以前经常有朋友要我帮他们写一个用服务器在后台发送邮件的程序,嫌麻烦,就在我自己的服务器上写了一段代码,以后别人要用服务器来发送邮件时,只需要在自己的程序中简单的写一行引用代码就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="[email protected]"> <input type=text name=name value="[email protected]"> <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的技术实现相差的太远了,但使用起来的方式却有点类似了. 
|