new Outlook.Application() thorws error if Outlook

2019-09-15 04:12发布

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?

2条回答
手持菜刀,她持情操
2楼-- · 2019-09-15 04:51

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

查看更多
beautiful°
3楼-- · 2019-09-15 05:08

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

查看更多
登录 后发表回答