您的位置:首页 > 大数据 > 人工智能

一个简单的邮件类[使用jmail组件发送]

2005-01-14 17:34 756 查看
<%
'****************************************************************************************
'*声 明:如果使用此程序请保留此段信息
'*程 序 名:TevMail
'*功 能:发送邮件(服务器上必须装有JMail4.3版本)
'*开发日期:2005-01-13
'*优 点:如果自己写的JMail程序,设置很多值,如服务器地址,密码,用户名,等等,使用本类后,最短
'* 只需要三行语句便可以发送邮件.具体操作请看下面的示例.
'*示 例:
'* Set abc = New JMail
'* abc.to = "您的信箱地址"
'* abc.send
'* <!-- #include file="路径/TevMail.asp" -->
'* 大家可以测试一下,用以上四句语句建立一个ASP页面,然后运行一下,你的邮件就发出去了!
'* 但如果我需要设置邮件标题,发件人,内容等等怎么办呢?请自己参阅下列参数.
'*具体参数:
'* .ServerAddress = "smtp.126.com" '此处设置自己的邮件服务器
'* .username = "weili.cn" '邮件服务器用户名
'* .password = "*******" '邮件服务器密码
'* .from = "weili.cn" '发件人地址
'* .Fromname = "liwei" '发件人姓名
'* .to = "weili.cn@126.com" '收件人姓名
'* .Subject = "测试" '邮件主题
'* .Body = "test" '邮件内容
'*错误处理:
'* .number '发送后可以用此值来判断是否发送成功,值<=0时则发送成功
'* .error '发送后如果有错误,可以用此值来提取错误信息
'* .about '当前类的版权信息,为了尊重他人成果,请勿修改,谢谢!
'****************************************************************************************
Class TevMail
Private ObjMail
Private sUserName
Private sPassword
Private sFrom
Private sFromName
Private sSubject
Private sBody
Private sTo
Private sServer
Private iNumber
Private sError
Private sAbout

Private Sub Class_Initialize()
sAbout = "程序名:邮件发送类<br>" & _
"编 写:Tellov<br>" & _
"日 期:2005-01-13<br>" & _
"备 注:欢迎使用本类,如果需要帮助或者有好的建议,请联系我,谢谢!<br>" & _
" Q Q :40386978<br>"& _
"EMail:weili.cn@126.com<br>"
sUserName = ""
sPassword = ""
sFrom = ""
sFromName = ""
sSubject = ""
sBody = ""
sTo = ""
sServer = ""
iNumber = 0
sError = ""

Set ObjMail = Server.CreateObject("JMail.Message")
with ObjMail
.silent = true
.Logging = true
.Charset = "gb2312"
.MailServerUserName = "tevmail"
.MailServerPassword = "tevmail"
.From = "tevmail@126.com"
.FromName = "Tellov"
.Subject = "欢迎使用JMail类!"
.Body = "本类由Tellov编写,欢迎大家交流学习,weili.cn@126.com"
end with
end Sub

Private Sub Class_Terminate()
Set ObjMail = nothing
end Sub

public Property Let ServerAddress(sInput)
sServer = sInput
end Property

Public Property Let UserName(sInput)
sUserName = sInput
end Property

Public Property Let Password(sInput)
sPassword = sInput
end Property

Public Property Let [To](sInput)
sTo = sInput
end Property

Public Property Let From(sInput)
sFrom = sInput
end Property

Public Property Let FromName(sInput)
sFromName = sInput
end Property

PubLic Property Let Subject(sInput)
sSubject = sInput
end Property

Public Property Let Body(sInput)
sBody = sInput
end Property

Public Property Get Number
Number = iNumber
end Property

Public Property Get Error
Error = sError
end Property

Public ProPerty Get About
About = sAbout
end Property

Private Function CheckAddress(sAddress)
Dim regEx,RegExpTest
Set regEx = New RegExp
regEx.Pattern = "^[/w/.]+@{1}/w+/.{1}/w+$"
regEx.IgnoreCase = false
RegExpTest = regEx.test(sAddress)
if RegExpTest then
CheckAddress = true
else
CheckAddress = false
end if
end Function

Private Function CheckMail()
if sServer = "" then
iNumber = -1
sError = sError & "您的[服务器地址]没有填写<br>"
end if

if sUsername = "" then
iNumber = -1
sError = sError & "您的[服务器用户名]没有填写<br>"
end if

if sPassword = "" then
iNumber = -1
sError = sError & "您的[服务器密码]没有填写<br>"
end if

if sFrom = "" then
iNumber = -1
sError = sError & "您的[发件人地址]没有填写<br>"
end if

if sFromName = "" then
iNumber = -1
sError = sError & "您的[发件人]没有填写<br>"
end if

if sSubject = "" then
iNumber = -1
sError = sError & "您的[邮件标题]没有填写<br>"
end if

if sBody = "" then
iNumber = -1
sError = sError & "您的[邮件内容]没有填写<br>"
end if

if sError <> "" then
sError = "以下选项您没有填写,程序将用默认配置发送邮件<br>" & sError
end if

if not CheckAddress(sTo) then
iNumber = 101
sError = "收件人地址格式不正确<br>"
end if

if sFrom<>"" and sUsername<>"" and sPassword<>"" and sServer<>"" and instr(sFrom,sUsername) = 0 and instr(sUsername,sFrom) = 0 then
iNumber = 102
sError = "发件人服务器用户名和发件地址不匹配<br>"
end if

if iNumber<=0 then
CheckMail = true
else
CheckMail = false
end if
end Function

Public Function Send()
on error resume next
if CheckMail() then
with ObjMail
if sFrom<>"" then
.From = sFrom
end if
if sFromName<>"" then
.FromName = sFromName
end if
if sSubject<>"" then
.Subject = sSubject
end if
if sBody<>"" then
.Body = sBody
end if
.AddRecipient sTo

if sUserName = "" or sPassWord = "" or sServer = "" then
.Send("smtp.126.com")
else
.MailServerUserName = sUserName
.MailServerPassword = sPassword
.Send(sServer)
end if
end With
end if

if err.number <> 0 then
iNumber = err.number
sError = err.Description & "<br>" & err.HelpContext
end if
End Function
end Class
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: