检索具有CLSID {0006F03A-0000-0000-C000-000000000046}的组件的COM类工厂失败。错误:80070005访问被拒绝

时间:2015-11-12 05:53:07

标签: asp.net outlook

在我的网站中,我正在创建Outlook对象并使用它们在按钮单击时打开Outlook文件。它在本地工作。但是当我在IIS 8.5中托管它时,它会给我以下错误

由于以下错误,检索具有CLSID {0006F03A-0000-0000-C000-000000000046}的组件的COM类工厂失败:80070005拒绝访问。 (HRESULT异常:0x80070005(E_ACCESSDENIED))。

我的代码如下:

outlook.Application objOutlk = new outlook.Application();
string templatePath = Server.MapPath("Files\\" + file + ".msg");
outlook._MailItem mailitem =   
(outlook.MailItem)objOutlk.CreateItemFromTemplate(templatePath);
mailitem.Display(true);

2 个答案:

答案 0 :(得分:0)

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

Consider using EWS in case of Exchange accounts, see EWS Managed API, EWS, and web services in Exchange for more information. Or Mail REST API can be used, see Outlook Mail REST API reference.

答案 1 :(得分:0)

首先,您不能在服务(例如IIS)中使用Outlook对象模型。其次,即使你可以,你的代码会做什么?它在运行代码的计算机上显示新创建的项目,即IIS服务器,而不是客户端计算机上。

如果要显示带有预先填充的To / CC / Subject / Body的新邮件窗口,请使用网页上的mailto:url。如果你想要更复杂的东西(例如带有图像的HTML主体等),你可以动态创建一个EML文件并让用户点击链接下载它 - 如果安装了Outlook,新的消息窗口将会打开。确保设置X-Unsent: 1 MIME标头。