1

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?

Builder
  • 1,046
  • 2
  • 10
  • 30

2 Answers2

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

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Yes my app is running in Visual Studio 2010 as Administrator. – Builder Mar 23 '17 at 15:12
  • Try to run it from Windows Explorer. Or run outlook as admin too. – Dmitry Streblechenko Mar 23 '17 at 15:13
  • 1
    Yes I tried it OutLook as admin and it works but what about other users not have admin rights on machine and running Oulook as normal user. This sending email feature will crash application – Builder Mar 23 '17 at 15:25
  • But they won't run your app as an admin either, right? As long as both security contexts are the same, it should work. – Dmitry Streblechenko Mar 23 '17 at 15:40
  • tried after publish it to IIS from IE with same priviledges and got this error Error sending a report: System.Runtime.InteropServices.COMException (0x80040111): Cannot create the e-mail message because a data file to send and receive messages cannot be found. Check your settings in this Microsoft Outlook profile. In Microsoft Windows, click the Start button, and then click Control Panel. Click User Accounts, and then click Mail. Click Show Profiles, select this profile, and then click Properties. The server is not available. Contact your administrator if this condition persists. at – Builder Mar 23 '17 at 15:51
  • I checked data files is there and selected as default – Builder Mar 23 '17 at 15:56
  • IIS? No Office app (including Outlook) can be used fom ma service (such as IIS). – Dmitry Streblechenko Mar 23 '17 at 15:59
  • Its an website using SQL server. I published it to local folder and run under IIS to check its normal behavior with Outlook. Now its giving me new error about data file. – Builder Mar 23 '17 at 16:04
  • Once again, you cannot do that. – Dmitry Streblechenko Mar 23 '17 at 16:04
2

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

Community
  • 1
  • 1
Builder
  • 1,046
  • 2
  • 10
  • 30