简体   繁体   中英

How to open Outlook new mail window on server C#

I am using this link for open outlook new mail window. How to open Outlook new mail window c#

But It is working fine On Local machine but when I deployed it on server it shows below error.

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

Microoft office outlook is install on local machine not on server.It is required to install and configure outlook on server. Plz help. Thanks.

1. Using Outlook

To send an email using outlook, we need to add a reference to the dynamic link library for Outlook which is called Microsoft.Office.Interop.Outlook.dll For the same follow the below steps:

  • Go to your solution explorer
  • Click on add a reference
  • Click on .Net Tab
  • Go through the DLL and select Microsoft.Office.Interop.Outlook.dll correctly.
  • when you have selected the correct reference you select the “OK” button and this reference will be added to your project under references.

     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 

    For more information Open outlook

  • 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 standard .Net classes or any other components designed for the server-side execution. In case of Exchange Server account you can use EWS (Exchange Web Services), see EWS Managed API, EWS, and web services in Exchange .

    If you run that code on the server, who will see the newly created message? Even if there is a user logged in locally to the server, IIS runs without a desktop session.

    If you want the message to be displayed on the client , that is where your code needs to run. Why not use a mailto url? It will work in any browser and the default email client will be opened. If you need something more sophisticated than that, you need to write your code in JavaScript and create an instance of the Outlook.Application object using new ActiveXObject(). You can only do that in IE and your site must be trusted to do that.

    The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM