'-----------------------------------------------------------------------
'--- 设置项
'-----------------------------------------------------------------------
'--- smtps教程erver 设置smtp邮件服务器地址
'--- fromemail 设置发件人的e-mail地址
'--- fromname 设置发送人名称
'--- contenttype 设置邮件类型 默认:text/html
'--- charset 设置编码类型 默认:gb2312
'--- sendobject 设置选取组件 1=jmail,2=cdonts
'-----------------------------------------------------------------------
'--- 属性
'-----------------------------------------------------------------------
'--- sendmail email, topic, mailbody 收件人地址,标题,邮件内容
'-----------------------------------------------------------------------
'--- 获取信息
'-----------------------------------------------------------------------
'--- errcode 信息编号 0=正常
'--- description 相应操作信息
'--- count 发送邮件数
'-----------------------------------------------------------------------
class lyout_mail
public count,errcode,errmsg
public username,password,fromemail,fromname
public smtpserver,contenttype,charset
private obj,cdoconfig,object
private sub class_initialize()
object = 0
count = 0
errcode = 0
contenttype = "text/html"
charset = "gb2312"
end sub
private sub class_terminate()
if isobject(obj) then
set obj = nothing
end if
if isobject(cdoconfig) then
set cdoconfig = nothing
end if
end sub
'获取错误信息
public property get description()
description = errmsg
end property
'设置选取组件 sendobject 0=jmail,1=cdonts,2=aspemail
public property let sendobject(byval value)
object = value
on error resume next
select case object
case 1
set obj = server.createobject("jmail.message")
case 2
set obj = server.createobject("cdonts.newmail")
case else
errnumber = 2
end select
if err<>0 then
errnumber = 3
end if
end property
private property let errnumber(byval value)
errcode = value
errmsg = errmsg & msg
end property
private function msg()
dim msgvalue
select case errcode
case 1
msgvalue = "未选取邮件组件或服务器不支持该组件!"
case 2
msgvalue = "所选的组件不存在!"
case 3
msgvalue = "错误:服务器不支持该组件!"
case 4
msgvalue = "发送失败!"
case else
msgvalue = "正常。"
end select
msg = msgvalue
end function
public sub sendmail(byval email,byval topic,byval mailbody)
if errcode <> 0 then
exit sub
end if
if email="" or isnull(email) then exit sub
if object>0 then
select case object
case 1
jmail email,topic,mailbody
case 2
cdonts email,topic,mailbody
case else
errnumber = 2
end select
else
errnumber = 1
end if
end sub
private sub jmail(email,topic,mailbody)
on error resume next
obj.silent = true
obj.logging = true
obj.charset = charset
if not(username = "" or password = "") then
obj.mailserverusername = username '您的邮件服务器登录名
obj.mailserverpassword = password '登录密码
end if
obj.contenttype = contenttype
obj.priority = 1
obj.from = fromemail
obj.fromname = fromname
obj.addrecipient email
obj.subject = topic
obj.body = mailbody
if err<>0 then
errmsg = errmsg & "发送失败!原因:" & err.description
errnumber = 4
else
if obj.send (smtpserver) then
obj.clearrecipients()
if err<>0 then
errmsg = errmsg & "发送失败!原因:" & err.description
errnumber = 4
else
count = count + 1
errmsg = errmsg & "发送成功!"
end if
else
errmsg = errmsg & "发送失败!原因:"&obj.log
errnumber = 4
end if
end if
end sub
private sub cdonts(email,topic,mailbody)
on error resume next
obj.from = fromemail
obj.to = email
obj.subject = topic
obj.bodyformat = 0
obj.mailformat = 0
obj.body = mailbody
if err<>0 then
errmsg = errmsg & "发送失败!原因:" & err.description
errnumber = 4
else
obj.send
if err<>0 then
errmsg = errmsg & "发送失败!原因:" & err.description
errnumber = 4
else
count = count + 1
errmsg = errmsg & "发送成功!"
end if
end if
end sub
end class
%>
|