Open Outlook with the same credentials as the running application.

I am writing a program that should open Microsoft Outlook and create a mail item for the user when he clicks a button. However, when I do this, I get the following error:

Extracting the COM class factory for a component with CLSID {0006F03A-0000-0000-C000-000000000046} failed with the following error: 80080005 Server Runtime Error (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). After investigating this error, I found out that my program and MS Outlook must run as administrator or as normal privilege level.

So here is my question ... How do I open MS Outlook using C # code using the same privilege level as my currently running program. I need to get the current privilege level and then open Outlook with that privilege level. I have had no luck in my research 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 working with an administrator. Then I don't get any errors.

Please suggest.

+3


source to share


2 answers


I am using SimpleMAPI.NET to open a standard email application and send an email. I even configured it to open a specific email application other than 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 here: http://www.codeproject.com/Articles/2048/Simple-MAPI-NET



If you find this approach workable for you, just leave a comment and I'll continue my answer with some code examples and my changes to SimpleMAPI.NET regarding Outlook (there are some issues with the original version above).

I'm suggesting this here because my team originally used Outlook over COM (as you are at the moment), ran into several issues with this, and then opted for my MAPI solution. It has proven to be much more stable versatile if one "only" wants to send an email via an external application ...

0


source


Outlook is a one-liner, so to make sure it's running at the same trust level as your application, your application must be the one that launches it.

  • You can try to kill Outlook first (not very good and the user will not appreciate it) before restarting it from your application.

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



Why is your app and Outlook running in different security contexts?

0


source







All Articles