ASP在线发E-mail的2个函数(使用JMail和NewMail组件)

作者:网络 来源:佚名 更新时间:2008-02-05 18:19:32 点击:
<%'by dicky qq:25941
function jmail(send_from,send_to,send_subject,send_body)
'调用jmail组件
'发送e-mail函数
'參數:
'send_from-發送者信箱
'send_to-接受者信箱
'send_subject-郵件主題
'send_body-郵件内容
dim jmail
set jmail = server.createobject("jmail.message")

jmail.charset = "gb2312" ' 邮件字符集,默认为"us-ascii"
' jmail.isoencodeheaders = false ' 是否进行iso编码,默认为true

' 发送者信息(可用变量方式赋值)
jmail.from = send_from ' 发送者邮箱
jmail.fromname = "管理员" ' 发送者姓名
jmail.subject = send_subject ' 邮件主题

' 身份验证
'jmail.mailserverusername = "user" ' 身份验证的用户名
'jmail.mailserverpassword = "password" ' 身份验证的密码

' 设置优先级,范围从1到5,越大的优先级越高,3为普通
jmail.priority = 3

jmail.addheader "originating-ip", request.servervariables("remote_addr")

' 加入一个收件人【变量send_from:收件人地址】可以同一语句重复加入多个
jmail.addrecipient(send_from)

' 邮件主体(html(注意信件内链接附件的方式))
jmail.htmlbody = ubbcode(send_body)
jmail.body = htmldecode(ubbcode(send_body))

' 发送【调用格式:objjmail.send([username:[email protected]]smtpserveraddress[:port])】
'jmail.send("user:[email protected]")
sendinfo=jmail.send(send_to)

' 关闭并清除对象
jmail.close()
set jmail = nothing
end function

function send_mail(send_from,send_to,send_subject,send_body)
'调用windows自带newmail组件
'发送e-mail函数
'參數:
'send_from-發送者信箱
'send_to-接受者信箱
'send_subject-郵件主題
'send_body-郵件内容
dim mailobject
set mailobject = server.createobject("cdonts.newmail")
mailobject.bodyformat = 0
mailobject.mailformat = 0
mailobject.from = send_from
mailobject.to = send_to
mailobject.subject = send_subject
mailobject.body = send_body
mailobject.send()
set mailobject = nothing

if err then
response.write "<script language=javascript>alert('error:"& err.number & err.description &"對不起,郵件發送失敗!:(');</script>"
else
response.write "<script language=javascript>alert('恭喜,郵件發送成功!^_^');</script>"
end if
end function %>