-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathclass_Email.cls
66 lines (59 loc) · 1.73 KB
/
class_Email.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "class_Email"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Attribute VB_Description = "Static class that allows sending multiple emails without having to create an Outlook.Application each time."
'@ModuleDescription "Static class that allows sending multiple emails without having to create an Outlook.Application each time."
'@PredeclaredId
Option Explicit
Private mMailApp As Object
Private Const APP_NAME As String = "Outlook.Application"
Public Sub GenerateEmail( _
ByVal ToRecipient As String, _
ByVal EmailSubject As String, _
ByVal EmailBody As String, _
Optional ByVal AutoSend As Boolean, _
Optional ByVal CCRecipient As String, _
Optional ByVal BCCRecipient As String _
)
If mMailApp Is Nothing Then Set mMailApp = CreateObject(APP_NAME)
With mMailApp
Dim OutMail As Object: Set OutMail = .CreateItem(0)
With OutMail
.To = ToRecipient
.CC = CCRecipient
.BCC = BCCRecipient
.Subject = EmailSubject
.Body = EmailBody
If AutoSend Then
.Send
Else
.Display
End If
End With
End With
End Sub
Public Sub Destroy()
On Error GoTo ErrorHandler
If Not mMailApp Is Nothing Then
mMailApp.Quit
Set mMailApp = Nothing
End If
Exit Sub
ErrorHandler:
If Err.Number > 0 Then
Debug.Print _
"Error Disposing of " & APP_NAME; ":" & vbCrLf _
& Err.Description
Err.Clear
Resume Next
End If
End Sub
Private Sub Class_Terminate()
Destroy
End Sub