尝试在邮件中打开Outlook附件时,通过IIS asp.net网站收到此错误。将具有DCOMCnfg完全权限的IIS USR和网络分配给Microsoft OutLook组件,但不起作用。
检索具有CLSID {0006F03A-0000-0000-C000-000000000046}的组件的COM类工厂因以下错误而失败:80070005访问被拒绝。 (HRESULT异常:0x80070005(E_ACCESSDENIED))。
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody = "Hello, This is test for sending pdf attachment using OutLook";
//Add an attachment.
String sDisplayName = "MyAttachment";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
//now attached the file
Outlook.Attachment oAttach = oMsg.Attachments.Add(Server.MapPath("~/TestSendFile.pdf"), iAttachType, iPosition, sDisplayName);
//Subject line
oMsg.Subject = "Your Subject will go here.";
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("user1@comecompany.com");
oRecip.Resolve();
// Send.
oMsg.Display();
答案 0 :(得分:2)
Outlook对象模型(就像任何其他Office应用程序一样)无法从服务(例如IIS)使用。 更重要的是,您试图在服务器一侧显示一条消息,没有人会看到它。
您可以使用
Exchange Web Services(如果是Exchange邮箱)
扩展MAPI(仅限C ++或Delphi)
Redemption - 它包装了扩展MAPI,其RDO family of objects可以在服务中使用。它可以从任何语言使用,包括C#。
如果您尝试在客户端方面显示消息,则选择