JavaScript+JMail邮件发送
代码如下,但还要加入jMail.dll并且注册它,可以到 http://www.fly263.com/Soft/ShowSoft.asp?SoftID=4 下载一个。
下载以后里面有一个 install.bat 文件双击就可以把jMail.dll等文件复制到c:/windows/system32里并且注册它,然后就可以用JavaScript发邮件了。
<html>
<head>
<title>mail</title>
<script>
function SendEMail(subject,infor)
{
var jMail = new ActiveXObject("Jmail.message");
jMail.Silent = true;
jMail.Charset = "gb2312";
jMail.FromName = "from name" //发件人
jMail.From = "from EMail"; //发送人的邮件地址
jMail.AddRecipient("to EMail"); //收件人的邮件地址
jMail.Subject = subject; //要发送的邮件主题
jMail.Body = infor; //要发送的邮件信息
jMail.MailServerUserName="from user name"; //发件人邮箱登陆名
jMail.MailServerPassWord="password"; //发件人邮箱登陆密码
var ret = jMail.Send("smtp.163.com"); //发件人的stmp服务器地址
if(ret == false)
{
alert("发送失败");
}
else
{
alert("发送成功");
}
jMail.Close();
}
SendEMail('title','body');
</script>
</head>
</html>
函数名:SendMail
'作 用:用Jmail组件发送邮件
'参 数:MailtoAddress -----收信人信箱
' MailtoName -----收信人姓名
' Subject -----主题
' MailBody -----信件内容
' MailFrom -----发信人信箱
' FromName -----发信人姓名
' Priority -----信件优先级
' MailServerUser -----登陆邮箱用户名
' MailServerPass -----登陆邮箱密码
' MailDomain -----邮箱域名
' MailServer -----发件SMTP服务器
'**************************************************
Function SendMail(MailtoAddress,MailtoName,Subject,MailBody,MailFrom,FromName,MailServerUser,MailServerPass,MailDomain,MailServer)
' on error resume next
Dim JMail,JMailstat
Set JMail=Server.CreateObject("JMail.Message")
if err then
err.clear
Response.Write "组件检测失败"
JMail.close()
Set JMail=nothing
exit function
end if
JMail.Charset="gb2312" '邮件字符集
JMail.silent=True '忽略错误
JMail.ContentType = "text/html" '邮件编码
JMail.AddRecipient MailtoAddress,MailtoName '收件人地址
JMail.ReturnReceipt = True '是否收条(验证中)
JMail.From = MailFrom '发件人邮箱
JMail.MailDomain=MailDomain '邮箱所在域名(验证中)
JMail.FromName = FromName '发件人姓名
JMail.MailServerUserName=MailServerUser '邮箱用户名
JMail.MailServerPassWord=MailServerPass '邮箱密码
JMail.Subject=Subject '邮件主题
JMail.Body=MailBody '邮件正文(纯文本格式)
'JMail.HMTLBody=MailBody '邮件正文(HTML格式)
JMail.Priority=1 '邮件等级,1为加急,3为普通,5为低级
JMailstat=JMail.Send(MailServer)
If JMailstat then
response.write "成功"
else
response.write "失败"
end if
JMail.close()
Set JMail=nothing
End Function
说明:
本文来源:http://www.pczs120.cn/articleshow.asp?artid=46
JMail4.5组件下载及中文操作手册下载详见http://www.pczs120.cn/softview.asp?softid=40v