近日,无事的时候在网上闲逛,无意搜索一个jmail,发现用jmail发送邮件的代码铺天盖地,信手拈来一用,真正能发送成功的寥寥无几。仔细一看,原来都是一样的。不知道是谁抄的谁,在网上就这样传开了。为了不让更多的人走弯路,把jmail发送邮件的函数整理如下,希望对各位有所帮助。
<%function sendMail()
On Error Resume Next
Dim objJMail, smtpServer, mailAddr, userName, password, shopName
Dim aryMailTo, strMailSubject, strMailBody, strMailTo
strMailTo ="abcd@163.com"'收件人邮箱地址列表,多个用英文逗号隔开
strMailSubject ="1234567"'可有可无
strMailBody = "你的的邮件内容"'邮件内容正文内容
shopName = "荣升网络"'发件人名称
smtpServer ="smtp.163.com"'邮件发送服务器
mailAddr = "123@163.com"'发件人邮箱
userName = "username"'发件人邮箱用户名
password = "password"'发件人邮箱密码
Set objJMail = Server.CreateObject("JMail.Message")
if Err.Number <> 0 then
exit function
end if
objJMail.Logging = true
objJMail.Charset = "gb2312"
objJMail.Silent = false
objJMail.Priority = 3
objJMail.MailServerUserName =mailaddr
objJMail.MailServerPassword = password
objJMail.From =mailaddr
objJMail.FromName =shopname
objJMail.Subject = "会员注册确认码"'邮件标题
if InstrRev(strMailTo, ",") = 0 then
objJMail.AddRecipient strMailTo
else
aryMailTo = Split(mailTo, ",")
for i = 0 to UBound(aryMailTo)
if aryMail(i) <> "" then
objJMail.AddRecipient aryMailTo(i)
end if
next
end if
objJMail.Body = "本邮件使用HTML格式,请以HTML方式查看本邮件。"
objJMail.HtmlBody = strMailBody
objJMail.AddHeader "Originating-IP",Request.ServerVariables("REMOTE_ADDR")
objJMail.Send(smtpServer)
objJMail.Close()
Set objJMail = Nothing
if Err.Number <> 0 then
Response.Write("发送失败:"& Err.Description)
Err.Clear()
else
Response.Write("发送成功")
end if
else
Response.Write("没有找到系统邮件发送相关配置资料,不能发信!")
end if
end function
%>
希望能对大家有一点点启发,更多的相关知识可以登陆我的网站http://www.66cs.com