ASP JMail cdonts Send mail class

Source: Internet
Author: User

'-----------------------------------------------------------------------
'---Set item
'-----------------------------------------------------------------------
'---SMTPS tutorial erver set SMTP mail server address
'---fromemail set the sender's e-mail address
'---fromname set sender name
'---contenttype set message type default: text/html
'---CharSet set encoding type default: gb2312
'---sendobject settings selection component 1=jmail,2=cdonts
'-----------------------------------------------------------------------
'---Property
'-----------------------------------------------------------------------
'---sendmail email, topic, Mailbody recipient address, title, email content
'-----------------------------------------------------------------------
'---get information
'-----------------------------------------------------------------------
'---errcode information number 0 = Normal
'---Description the corresponding operation information
' Count the number of messages sent---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
' Get the error message
Public Property Get Description ()
Description = ErrMsg
End Property
' Set selection component 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 = "The message component is not selected or the server does not support this component!" "
Case 2
Msgvalue = "The selected component does not exist! "
Case 3
Msgvalue = "Error: Server does not support this component!"
Case 4
Msgvalue = "Send failed!"
Case Else
Msgvalue = "normal". "
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 ' your mail server login name
Obj.mailserverpassword = password ' login 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 & send failed! Reason: & Err.Description
Errnumber = 4
Else
If Obj.send (smtpserver) Then
Obj.clearrecipients ()
If Err<>0 Then
ErrMsg = errmsg & send failed! Reason: & Err.Description
Errnumber = 4
Else
Count = Count + 1
ErrMsg = errmsg & "Send success!"
End If
Else
ErrMsg = errmsg & Send failed! Reason: "&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 & send failed! Reason: & Err.Description
Errnumber = 4
Else
Obj.send
If Err<>0 Then
ErrMsg = errmsg & send failed! Reason: & Err.Description
Errnumber = 4
Else
Count = Count + 1
ErrMsg = errmsg & "Send success!"
End If
End If
End Sub
End Class
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.