Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting COMException when accessing Emails on Outlook 2010

Hello I am trying to access my emails in Outlook 2010 via a C# Console Application.

Visual Studio is started with admin rights and I have added a reference to Microsoft.Office.Interop.Outlook v14.0.0.0 and used it as Outlook.

My Code:

Console.Write("starting");
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = app.GetNamespace("MAPI");
Outlook.MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Console.WriteLine(((Outlook.MailItem)myInbox.Items[0]).Subject);
Console.WriteLine("readline:");
Console.ReadLine();

The second line, throws an error message:

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)).

Do you know any solutions?

like image 641
Niklas Avatar asked Feb 11 '13 09:02

Niklas


1 Answers

It is because of privileges of the process.Please run Visual studio and outlook as administrator.

Simple solution. Run both as administrator or run both as normal privilege level.

Regards Rameez Ali

like image 126
RameezAli Avatar answered Nov 14 '22 23:11

RameezAli