SecurityManager not releasing Outlook

Add-in Express™ Support Service
That's what is more important than anything else

SecurityManager not releasing Outlook
SecurityManager not releasing Outlook 
Peter Wordsworth




Posts: 11
Joined: 2023-01-17
Hi, just wondering if you can help me with an issue i am having with the SecurityManager ActiveX control (version 10.0.1400).

I installed the control on my development machine (Windows 10 64bit) using the Setup program. I am running Outlook version "Microsoft??? Outlook??? for Microsoft 365 MSO (Version 2211 Build 16.0.15831.20098) 64-bit".

When i run your sample VB6 program "SendMail" with "Security Off" selected the instance of Outlook which is created remains open after the "SecurityManager1.Disconnect" and "IOutlook = Nothing" code is executed. Even when the application is closed a hidden Outlook icon remains on the taskbar which says "Another Program is using Outlook. To disconnect programs and exit Outlook, click the Outlook icon and then click Exit Now" .

When I run "SendMail" with "Security On" (i.e. no SecurityManager code is referenced) the instance of Outlook closes as expected.

I take it this is not expected behaviour?

Cheers

Peter
Posted 17 Jan, 2023 07:36:22 Top
Andrei Smolin


Add-in Express team


Posts: 18995
Joined: 2006-05-11
Hello Peter,

No, this isn't. I reproduce the issue on a 32-bit Outlook. Checking it.

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Jan, 2023 11:31:50 Top
Andrei Smolin


Add-in Express team


Posts: 18995
Joined: 2006-05-11
Hello Peter,

The following works for me.

Instead of connecting the OutlookSecurityManager1 component to IOutlook, connect it to IOutlookExpl. When disconnecting, replace IOutlook with IOutlookExpl, too. And when finishing the code, add IOutlook.Quit. Does this work for you?

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader

Private Sub Command1_Click()
Dim IOutlook As Object
Dim IOutlookExpl As Object
Dim IMail As Object
Dim IRecipient As Object
Dim Resolved As Boolean

If Text1.Text = "" Then
  MsgBox ("You need to fill in the 'To...' field.")
Else
  Set IOutlook = CreateObject("Outlook.Application")
  Set IOutlookExpl = IOutlook.GetNamespace("MAPI").GetDefaultFolder(6).GetExplorer ' 6 = olFolderInbox
  On Error GoTo finally1
    Set IMail = IOutlook.CreateItem(olMailItem)
    If Option2.Value = True Then
      Call OutlookSecurityManager1.ConnectTo(IOutlookExpl)
      OutlookSecurityManager1.DisableOOMWarnings = True
    End If
    On Error GoTo finally2

    On Error Resume Next
    If Text1.Text <> "" Then
      On Error Resume Next
      IRecipient = IMail.Recipients.Add(Text1.Text)
      If Err = 287 Then GoTo error1
      IRecipient.type_ = 1 'olTo
      IRecipient.Resolve
    End If
    If Text2.Text <> "" Then
      On Error Resume Next
      IRecipient = IMail.Recipients.Add(Text2.Text)
      If Err = 287 Then GoTo error1
      IRecipient.type_ = 2 'olCC
      IRecipient.Resolve
    End If
    If Text3.Text <> "" Then
      On Error Resume Next
      IRecipient = IMail.Recipients.Add(Text3.Text)
      If Err = 287 Then GoTo error1
      IRecipient.type_ = 3 'olBCC
      IRecipient.Resolve
    End If
    IMail.Subject = Text4.Text
    IMail.Body = Text5.Text
    On Error GoTo error1
    IMail.Send
    MsgBox ("The message has been sent successfully.")
    GoTo finally2
error1:
    MsgBox Err.Description
finally2:
    If Option2.Value = True Then
      OutlookSecurityManager1.DisableOOMWarnings = False
      OutlookSecurityManager1.Disconnect IOutlookExpl
    End If
finally1:
    Set IRecipient = Nothing
    Set IMail = Nothing
    Call IOutlookExpl.Close
    Set IOutlookExpl = Nothing
    Call IOutlook.Quit
    Set IOutlook = Nothing
'  End
End If
End Sub
Posted 18 Jan, 2023 11:04:32 Top
Peter Wordsworth




Posts: 11
Joined: 2023-01-17
Hi Andrei, your suggestion worked. I had to remove the code "Call IOutlook.Quit" though as it generated an error.

Thanks for your help.

Cheers
Posted 18 Jan, 2023 17:59:36 Top
Andrei Smolin


Add-in Express team


Posts: 18995
Joined: 2006-05-11
It's great.

Peter Wordsworth writes:
I had to remove the code "Call IOutlook.Quit" though as it generated an error.


But it's strange.

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 19 Jan, 2023 03:57:55 Top
Peter Wordsworth




Posts: 11
Joined: 2023-01-17
Hi, i found another issue that perhaps you could help with. In my application i often create and display an Outlook email without saving it to the drafts folder first. This gives the user a chance to edit the email before sending it or saving it to Drafts.

When i execute the code "IOutlookExpl.Close" Outlook displays a prompt asking if you wish to save the newly displayed email. If you select either 'yes' or 'no' it then closes the email immediately. If you select Cancel it leaves the email open but doesn't release the Outlook process after the email it eventually sent.

To see an example of this in your sample code (above) change IMail.Send to IMail.Display. Is there a workaround for this? I tried moving IMail.Display after IOutlookExpl.Close but thats a no go.

Cheers
Posted 29 Jan, 2023 21:07:34 Top
Andrei Smolin


Add-in Express team


Posts: 18995
Joined: 2006-05-11
Hello Peter,

Peter Wordsworth writes:
When i execute the code "IOutlookExpl.Close" Outlook displays a prompt asking if you wish to save the newly displayed email. If you select either 'yes' or 'no' it then closes the email immediately. If you select Cancel it leaves the email open but doesn't release the Outlook process after the email it eventually sent.


These are expected: if an email is left open, Outlook stays as well. We discuss a scenario where you start Outlook programmatically, correct? I don't understand what you need to achieve. Could you please explain?

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Feb, 2023 05:06:02 Top
nappsoft




Posts: 1
Joined: 2023-10-31
Hi there

I have the same problem with a Delphi based application. Wanted to try the OutlookExplorer workaround, however with the VCL interface it is not possible to connect to an Outlook Explorer Object: When trying to securityManager.ConnectTo(outlookExpl) I get a "Method 'Version' not supported by automation object" EOleException.

outlookApp := CreateOleObject('Outlook.Application');
outlookExp := outlookApp.GetNameSpace('MAPI').GetDefaultFolder(6).GetExplorer;
securityManager := TOlSecurityManager.Create(nil);
securityManager.ConnectTo(outlookExp);

Best regards,

Pirmin
Posted 31 Oct, 2023 07:19:37 Top
Andrei Smolin


Add-in Express team


Posts: 18995
Joined: 2006-05-11
Hello Pirmin,

I've sent you a fixed DLL that solves this issue.

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 31 Oct, 2023 14:27:54 Top
Andrei Smolin


Add-in Express team


Posts: 18995
Joined: 2006-05-11
Please check you Inbox.

Regards from Poland (GMT+1),

Andrei Smolin
Add-in Express Team Leader
Posted 31 Oct, 2023 14:28:51 Top