| 1 |
Attribute VB_Name = "ModuleMailer" |
| 2 |
' (c) Andreas Motl <andreas.motl@ilo.de>, 2007-09-01 |
| 3 |
|
| 4 |
Option Explicit |
| 5 |
|
| 6 |
Const showProfileChooser As Boolean = True |
| 7 |
Const outlookProfileName As String = "x" |
| 8 |
Const outlookProfilePass As String = "" |
| 9 |
|
| 10 |
Dim mailer As Outlook.Application |
| 11 |
Dim mailerAlreadyRunning As Boolean |
| 12 |
|
| 13 |
Public Function mailerCheckRunning() As Boolean |
| 14 |
Dim tmp As Variant |
| 15 |
On Error Resume Next |
| 16 |
tmp = mailer.ActiveExplorer.WindowState |
| 17 |
If Err.Number = 0 Then mailerCheckRunning = True |
| 18 |
On Error GoTo 0 |
| 19 |
End Function |
| 20 |
|
| 21 |
Public Function mailerStart() |
| 22 |
|
| 23 |
slog "creating mailer-object" |
| 24 |
Set mailer = New Outlook.Application |
| 25 |
DoEvents |
| 26 |
DoEvents |
| 27 |
|
| 28 |
mailerAlreadyRunning = mailerCheckRunning() |
| 29 |
|
| 30 |
If mailerAlreadyRunning Then |
| 31 |
slog "*not* logging on, using running mailer" |
| 32 |
Else |
| 33 |
If showProfileChooser Then |
| 34 |
slog "logging in (using Profile-Chooser), this may take some seconds!" |
| 35 |
mailer.Session.Logon , , 1 |
| 36 |
DoEvents |
| 37 |
DoEvents |
| 38 |
Else |
| 39 |
slog "logging in (auto-selecting profie " & outlookProfileName & "), this may take some seconds!" |
| 40 |
mailer.Session.Logon outlookProfileName, outlookProfilePass, 0 |
| 41 |
End If |
| 42 |
End If |
| 43 |
|
| 44 |
End Function |
| 45 |
|
| 46 |
Public Function mailerShutdown() |
| 47 |
|
| 48 |
slog "logging off" |
| 49 |
mailer.Session.Logoff |
| 50 |
|
| 51 |
If mailerAlreadyRunning Then |
| 52 |
slog "*not* quitting running mailer!" |
| 53 |
Else |
| 54 |
slog "closing active mail-explorer" |
| 55 |
mailer.ActiveExplorer.Close |
| 56 |
slog "quitting mailer" |
| 57 |
mailer.Quit |
| 58 |
End If |
| 59 |
|
| 60 |
slog "destroying mailer-object" |
| 61 |
Set mailer = Nothing |
| 62 |
|
| 63 |
End Function |