Security Manager leaves Outlook running in the Windows System Tray when built with Any CPU

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

Security Manager leaves Outlook running in the Windows System Tray when built with Any CPU
 
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Hello Chris,

Chris Dewar-English writes:
The build configuration bitness does seem to cause the Security Manager to behave differently.


We can't confirm the issue; we are unable to reproduce it on our machines.

Try this approach:

Outlook._Application outlookApp = null;
Outlook._MailItem newMail = null;
Outlook.Recipient recipient = null;
Outlook.Recipients recipients = null;
Type olType = Type.GetTypeFromProgID("Outlook.Application", false);
if (olType != null) {
    bool canQuit = true;
    try {
        outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook._Application;
        if (outlookApp != null) canQuit = false;
    } catch {
    }
    try {
        if (outlookApp == null)
            outlookApp = Activator.CreateInstance(olType) as Outlook._Application;
    } catch {
    }
    if (outlookApp != null) {
        Outlook._Inspector inspector = null;
        try {
            newMail = outlookApp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
            if (newMail != null) {
                inspector = newMail.GetInspector;
                if (tbtnMode.Pushed) {
                    securityManager1.ConnectTo(inspector);
                    securityManager1.DisableOOMWarnings = true;
                }
                try {
                    recipients = newMail.Recipients;
                    if (txbTO.Text != String.Empty) {
                        recipient = recipients.Add(txbTO.Text);
                        recipient.Type = (int)Outlook.OlMailRecipientType.olTo;
                        recipient.Resolve();
                        Marshal.ReleaseComObject(recipient);
                    }
                    if (txbCC.Text != String.Empty) {
                        recipient = recipients.Add(txbCC.Text);
                        recipient.Type = (int)Outlook.OlMailRecipientType.olCC;
                        recipient.Resolve();
                        Marshal.ReleaseComObject(recipient);
                    }
                    if (txbBCC.Text != String.Empty) {
                        recipient = recipients.Add(txbBCC.Text);
                        recipient.Type = (int)Outlook.OlMailRecipientType.olBCC;
                        recipient.Resolve();
                        Marshal.ReleaseComObject(recipient);
                    }

                    newMail.Subject = txbSubject.Text;
                    newMail.Body = txbMail.Text;

                    newMail.Send();

                    Marshal.ReleaseComObject(recipients);
                    Marshal.ReleaseComObject(newMail);

                    MessageBox.Show("The message has been sent successfully.", "Send Mail", MessageBoxButtons.OK, MessageBoxIcon.Information);
                } catch (Exception err) {
                    if (recipients != null)
                        Marshal.ReleaseComObject(recipients);
                    if (newMail != null)
                        Marshal.ReleaseComObject(newMail);

                    MessageBox.Show(err.Message, err.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        } finally {
            Marshal.ReleaseComObject(inspector);
            Marshal.ReleaseComObject(outlookApp);
        }
    }
}


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 11 Jul, 2016 09:41:20 Top
Chris Dewar-English




Posts: 11
Joined: 2013-04-22
Thank you. Ok, so using the MailItem's Inspector for the SecurityManager to connect with solves the problem - Outlook closes on its own once the MailItem has been processed. I should be able to work with that.

Can you clarify one thing please? It isn't clear in the previous messages which part of the issue you could not confirm:-

You were not able to reproduce the original issue of Outlook not closing when launching from a cold start when using SecMan and the original sample without the Quit method being called? Did Outlook always close for you even without the Quit being called? This is the behaviour I see when using Outlook without the Security Manager, but with SecMan I found Outlook never exited.

or, did you find you could actually reproduce this issue but the part you could not reproduce was my x86 build configuration 'fix'?

Thank you for your time.

Regards,

Chris Dewar-English
Posted 12 Jul, 2016 04:32:32 Top
Andrei Smolin


Add-in Express team


Posts: 14140
Joined: 2006-05-11
Chris,

Chris Dewar-English writes:
It isn't clear in the previous messages which part of the issue you could not confirm


That's a good point!

We were unable to reproduce any issue related to to the platform for which the original SendMail sample project was built. As you can see this may be quite different from what you tested. I suggest that you send us a project that reproduces the bitness-related issue for you; find the support email address in {Add-in Express installation folder}\readme.txt. Please make sure your email contains a link to this topic.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Jul, 2016 06:02:09 Top