<%@Language="JScript" codepage="936"%>
<%
function aspMailClass(){
var fromMail = "test@test.com"; //发件人邮箱
var fromServ = "smtp.test.com"; //smtp服务器
var fromProt = 25; //smtp服务器端口
var fromName = "无忧脚本"; //发件人姓名
var fromUser = "51js"; //发件人邮箱用户名
var fromPass = "51js"; //发件人邮箱密码
this.sendMail = function(toEmail, toTitle, toBody){
try {
var byMail = new ActiveXObject("CDO.Configuration");
var fields = byMail.Fields;
var cfgUrl = "http://schemas.microsoft.com/cdo/configuration/";
fields(cfgUrl + "sendusing") = 2; //这里是发送邮件的端口
fields(cfgUrl + "smtpserver") = fromServ; //smtp服务器
fields(cfgUrl + "smtpserverport") = fromProt; //smtp服务器端口
fields(cfgUrl + "smtpaccountname") = fromMail; //发件人帐号名称
fields(cfgUrl + "sendemailaddress") = fromMail; //发件人的信箱
fields(cfgUrl + "smtpauthenticate") = 1; //是否认证
fields(cfgUrl + "sendusername") = fromUser; //发件人邮箱用户名
fields(cfgUrl + "sendpassword") = fromPass; //发件人邮箱密码
fields.Update();
var oMail = new ActiveXObject("CDO.Message");
with(oMail){
To = toEmail;
Subject = toTitle;
HTMLBody = toBody;
From = fromName + "<" + fromMail + ">";
Configuration = byMail;
Mimeformatted = true;
AutoGenerateTextBody = true;
Fields.Update();
HTMLBodyPart.Charset = "gb2312";
Send();
}
oMail = null;
fields = null;
byMail = null;
return this.result = "邮件成功发送至" + toEmail + "!";
}
catch(e) {
return this.result = "发送至" + toEmail + "的邮件发送失败!失败原因:" + e.description;
}
}
}
//实例
var toMail = new aspMailClass();
toMail.sendMail("xxx@xxx.com", "欢迎来到无忧脚本", "主题<font color=red>主题2</font>");
Response.Write(toMail.result);
toMail = null;
%>
posted on 2007-06-16 15:30
汪杰 阅读(431)
评论(0) 编辑 收藏 引用 所属分类:
asp(javascrpt)