ASP+XMLHTTP跨主机调用Jmail发送邮件[网站编程]
本文“ASP+XMLHTTP跨主机调用Jmail发送邮件[网站编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
“ASP+XMLHTTP跨主机调用Jmail发送邮件” 所要办理的问题是在不支持Jmail组件的服务器上实现邮件的发送.
(国内大多IDC主机都是支持Jmail组件的)
实现原理其实也很简单:
(1)我们需求一台支持Jmail组件的主机,在其Web目录安排我们的“Jmail远程调用接口文件 MailApi.asp”(后附源代码), 该文件的功效是接纳参数(接纳者邮箱,邮件主题,邮件内容,发送者名称等信息),并调用Jmail发送邮件. 假定这个地址是:http://www.taoyard.com/MailApi.asp.
(2)在需求发送邮件但不支持Jmail的主机上,通过XMLHTTP向“接口文件 MailApi.asp”POST邮件参数.将SendMail.asp安排于该主机的Web目录,在需求发邮件的位置调用SendMail函数便可.
存在的问题:
没有加入身份认证,在得知接口文件地址后任何人都能调用该接口发送邮件,增添了主机的压力.
附源代码:
<%
ASP+XMLHTTP跨主机调用Jmail发送邮件
by redice 2009.8.24
http://www.redicecn.cn
MailApi.asp Jmail远程调用接口文件
response.Charset="gb2312"
dim receiver
dim subject
dim content
dim sendername
receiver=filter(request("receiver"))
subject=filter(request("subject"))
content=filter(request("content"))
sendername=filter(request("sendername"))
response.write receiver & "," & subject & "," & content & "," & sendername & "<br>"
if receiver="" or subject="" or content="" or sendername="" then
response.write "邮件信息不完好!"
response.end
end if
SendMail receiver,subject,content,sendername
---------------------------------Jmail发送电子邮件函数----------------------------
SMTP等相关信息设置
Const SenderEmail="发送者邮箱"
Const Smtp="SMTP服务器地址"
Const UserName="SMTP用户名"
Const Password="SMTP密码"
Public Function SendMail(Receiver,Subject,Content,SenderName)
dim msg
Set msg = Server.CreateObject("JMail.Message")
msg.silent = true
msg.Logging = true
msg.Charset = "gb2312"
msg.MailServerUserName = UserName
msg.MailServerPassword = Password
msg.From = SenderEmail
msg.FromName = SenderName
msg.AddRecipient Receiver
msg.Subject = Subject
msg.Body = Content
msg.Send (Smtp)
msg.close()
set msg = nothing
End Function
Function filter(str)
filter=replace(str,"","")
End Function
response.write "发送邮件成功!"
%>
<%
ASP+XMLHTTP跨主机调用Jmail发送邮件
by redice 2009.8.24
http://www.redicecn.cn
SendMail.asp 邮件发送函数所在文件
response.Charset="gb2312"
Jmail远程接口文件(MailApi.asp)地址
Const MailApiUrl="按照实际情形改正"
邮件发送调用函数
function SendMail(Receiver,Subject,Content,SenderName)
dim querystring
querystring="receiver=" & receiver
querystring=querystring & "&subject=" & server.urlencode(subject)
querystring=querystring & "&content=" & server.urlencode(content)
querystring=querystring & "&sendername=" & server.urlencode(sendername)
response.write querystring & "<br>"
dim xmlHttp
set xmlHttp=Server.CreateObject("Micro"&"soft"&"."&"XML"&"HTTP")
xmlHttp.open "post",MailApiUrl,false
xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlHttp.send querystring & vbcrlf & vbcrlf
response.write xmlHttp.responseText
end function
测试示例
SendMail "redice@163.com","主题","内容","redice"
%>
以上是“ASP+XMLHTTP跨主机调用Jmail发送邮件[网站编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |