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.