3
votes

I'm writing a program that needs to open up Microsoft Outlook and create a mail item for the user when they click on a button. However, when I do so, I get the following error:

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000- 000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). After researching this error I found out that my program and MS Outlook must both be run as administrator or as normal privilege level.

So here's my question... How do I open MS Outlook through the C# code by using the same privilege level as my current running program. I need to get the current privilege level, then open Outlook with that privilege level. I've had no luck in my research with this so far. Any help is appreciated!

Here's my code (currently) for opening MS Outlook and how I use it:

Application outlookApp = new Application();

MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem);
mailItem.Subject = "Blah";
mailItem.HTMLBody= @"Various HTML stuff";

foreach (string documentPath in this.documentPaths)
{
    mailItem.Attachments.Add(documentPath, 1, 1, documentPath);
}

mailItem.Display(true);

I am using Microsoft.Office.Interop.Outlook. If outlook is already running with administrator. Then I don't get any error.

Please suggest.

2

2 Answers

0
votes

Outlook is a singleton, so to make sure it is running on the same trust level as your app, your app must be the one that starts it.

  1. You can try to kill Outlook first (not very nice and the user won't appreciate it) before restarting it from your app.

  2. You can use Extended MAPI (C++ or Delphi) or Redemption (it wraps Extended MAPI and can be used from any language) - MAPI is loaded in-proc, so it will work even if Outlook is already running. But you will not be able to display the items: outlook.exe is the one that ends up displaying messages even if you use MAPI, so you are back where you started.

Why do your app and Outlook end up running in different security contexts?

0
votes

I am using SimpleMAPI.NET to open the standard email application and send an email. I have even tuned it to open a specific email application, different from the one configured in windows. Works great with MS Outlook so far and can even be used with other email software.

SimpleMAPI.NET can be obtained from here: http://www.codeproject.com/Articles/2048/Simple-MAPI-NET

If you deem this approach workable for you, just leave a comment and I will extend my answer by some code examples and my modifications to SimpleMAPI.NET regarding Outlook (there are some issues with the original version above).

I am proposing this here, because my team initially was using Outlook via COM (as you do, at the moment), faced several issues with this and then opted for my MAPI solution. It has proven to be much more stable an versatile, if one "only" wants to send an email via an external application...