0
votes

In my website, i am creating Outlook objects and using them to open an outlook file on a button click. It works locally. but when i host it in IIS 8.5 it gives me the following error

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

My code is as follows:

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

2 Answers

0
votes

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.

0
votes

Firstly, you cannot use the Outlook Object Model in a service (such as IIS). Secondly, even if you could, what would your code do? It displays the newly created item on the machine where your code is running, i.e. your IIS server, not on the client machine.

If you want to display a new mail window with prepopulated To/CC/Subject/Body, use the mailto: url on your web page. If you want something more sophisticated (e.g. HTML body with images etc.), your can dynamically create an EML file and make the user click on a link to download it - if Outlook is installed, the new message window will open. Make sure to set the X-Unsent: 1 MIME header.