如果 Outlook 应用程序是 运行,则新的 Outlook.Application() 会引发错误

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

您好,我遇到了类似的问题

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

但想要定制解决方案。

我想发送带有我的代码适用的附件的电子邮件,但是如果 OutLook 应用程序已经作为桌面应用程序打开,那么我会收到此错误。

要求:我想打开 outlook window 显示我们在 window 中撰写消息时的所有内容。

我正在这样做:

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

如果 OutLook 应用程序是 运行,则会出现此错误。

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

当我关闭 OutLook 时,没有出现任何错误,一切都如我所愿。我不想像这里建议的其他解决方案那样以编程方式关闭 OutLook

再提一件事我正在使用 Microsoft.Office.Interop.Outlook.dll 这是 32 位/64 位问题吗?或者必须使用其他一些新的 Dll?

错误是CO_E_SERVER_EXEC_FAILURE。如果您的应用程序和 Outlook 的安全上下文不同,很可能会发生这种情况。任一应用 运行 是否提升了权限(运行 作为管理员)?

我终于找到了答案。我测试了它的工作。

  1. 在开始菜单中 select 运行
  2. 键入 dcomcnfg 并单击“确定”
  3. 组件服务 window 已打开。
  4. 展开节点组件服务 -> 我的电脑 -> DCOM 配置。
  5. 右键单击应用程序(Outlook 邮件附件)和 select 属性。
  6. 根据需要单击“身份”选项卡。
  7. 点击“交互用户”然后确定

在这里找到

Click Here