【问题标题】:How to open Outlook new mail window on server C#如何在服务器 C# 上打开 Outlook 新邮件窗口
【发布时间】:2015-04-26 03:09:46
【问题描述】:

我正在使用此链接打开 Outlook 新邮件窗口。 How to open Outlook new mail window c#

但它在本地机器上运行良好,但是当我将它部署在服务器上时,它显示以下错误。

检索具有 CLSID 的组件的 COM 类工厂 {0006F03A-0000-0000-C000-000000000046} 由于以下原因而失败 错误:80040154 类未注册(HRESULT 异常: 0x80040154 (REGDB_E_CLASSNOTREG))。

Microoft Office Outlook 安装在本地机器上而不是服务器上。需要在服务器上安装和配置 Outlook。 请帮忙。 谢谢。

【问题讨论】:

  • 如果服务器上没有安装outlook,就不能在服务器上使用。

标签: c# email outlook


【解决方案1】:

1.使用 Outlook

要使用 Outlook 发送电子邮件,我们需要添加对 Outlook 动态链接库的引用,该库称为 Microsoft.Office.Interop.Outlook.dll 同样,请按照以下步骤操作:

  • 转到您的解决方案资源管理器
  • 点击添加参考
  • 单击 .Net 选项卡
  • 通过 DLL 并选择 Microsoft.Office.Interop.Outlook.dll 正确。
  • 当您选择了正确的参考时,您选择“确定”按钮,该参考将添加到您的项目中的参考下。
    using Outlook = Microsoft.Office.Interop.Outlook;
    //method to send email to outlook
    public void sendEMailThroughOUTLOOK()
    {
        try
        {
        // 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, Jawed your message body will go here!!";
        //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(@"C:\\fileName.jpg", 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("jawed.ace@gmail.com");
        oRecip.Resolve();
        // Send.
        oMsg.Send();
        // Clean up.
        oRecip = null;
        oRecips = null;
        oMsg = null;
        oApp = null;
         }//end of try block
        catch (Exception ex)
        {
        }//end of catch
    }//end of Email Method
    

    欲了解更多信息Open outlook

  • 【讨论】:

    • 这是在本地工作,但不在服务器上。我还添加了DLL。发生了同样的错误。
    【解决方案2】:

    Microsoft 目前不推荐也不支持从任何无人值守的非交互式客户端应用程序或组件(包括 ASP、ASP.NET、DCOM 和 NT 服务)自动化 Microsoft Office 应用程序,因为 Office在此环境中运行 Office 时可能会出现不稳定的行为和/或死锁。

    如果您要构建在服务器端上下文中运行的解决方案,您应该尝试使用已确保无人值守执行安全的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方案。如果您使用服务器端解决方案中的 Office 应用程序,该应用程序将缺少许多成功运行所需的功能。此外,您将在整体解决方案的稳定性方面承担风险。

    Considerations for server-side Automation of Office 文章中了解更多信息。

    考虑使用标准 .Net 类或为服务器端执行而设计的任何其他组件。如果是 Exchange Server 帐户,您可以使用 EWS(Exchange Web 服务),请参阅EWS Managed API, EWS, and web services in Exchange

    【讨论】:

      【解决方案3】:

      如果您在服务器上运行该代码,谁会看到新创建的消息?即使有用户在本地登录到服务器,IIS 也会在没有桌面会话的情况下运行。

      如果您希望消息显示在客户端上,那就是您的代码需要运行的地方。为什么不使用mailto url?它可以在任何浏览器中运行,并且默认的电子邮件客户端将被打开。如果您需要比这更复杂的东西,您需要用 JavaScript 编写代码并使用 new ActiveXObject(). 创建 Outlook.Application 对象的实例。您只能在 IE 中执行此操作,并且您的站点必须被信任才能执行此操作。

      【讨论】:

        猜你喜欢
        • 2016-05-30
        • 1970-01-01
        • 2011-05-31
        • 2023-03-13
        • 1970-01-01
        • 2013-10-08
        • 1970-01-01
        • 1970-01-01
        • 2012-07-29
        相关资源
        最近更新 更多