new Outlook.Application() thorws error if Outlook app is running

0

Hi I am having similar issue

CreateObject on Outlook.Application fails on Outlook 2010 when Outlook is running under a different account

but want customized solution.

I want to sent email with attachment for which my code works but if OutLook app is already opened as desktop app, then I am getting this error.

Requirement: I want to open outlook window showing everything like when we compose message in window.

I am doing this:

Microsoft.Office.Interop.Outlook.Application outlookApp = new Outlook.Application();

Getting this error if OutLook app is running.

Error sending a report: System.Runtime.InteropServices.COMException (0x80080005): 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)).
at ReportViewerControl.SendOutLookMail_Click(Object sender, EventArgs e) in c:\Projects\MSCatalog\MS SQLSERVER\Web\UserControls\Reports\ReportViewerControl.ascx.cs:line 262

When I close OutLook no error and everything works like I want. I dont want to close OutLook pro grammatically as other solutions suggested here

Just 1 more thing to mention that I am using Microsoft.Office.Interop.Outlook.dll is this 32bit/64bit problem? Or have to use some other new Dll?

email
outlook
com
asked on Stack Overflow Mar 23, 2017 by Builder • edited Mar 23, 2017 by Builder

2 Answers

3

The error is CO_E_SERVER_EXEC_FAILURE. Most likely this happens if the security context of your app and Outlook are different. Is either app running with elevated privileges (Run As Administrator)?

1

Finally I found my answer. I tested and its working.

  1. In start menu select Run
  2. Type dcomcnfg and click OK
  3. Component Services window is opened.
  4. Expand the nodes Component Services -> MyComputer -> DCOM Config .
  5. Right click on the application (Outlook Message Attachment) and select properties.
  6. Click on Identity tab whatever necessary.
  7. Click on “The interactive user" then OK

Found it here

Click Here

answered on Stack Overflow Mar 23, 2017 by Builder • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0