1

I am creating an application page and hence creatig a button in asp.net c# that when clicked will open up Outlook window.

I am referencing to the Microsoft.Office.Interop.Outlook dll, and using this in using statement:

using Outlook = Microsoft.Office.Interop.Outlook;

This the code.

        private void CreateMailItem()            
        {
            try

            {
                var outlookApp = new Outlook.Application();

                var mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

                //var mailItem = (Outlook.MailItem)
                //    Application.CreateItem(Outlook.OlItemType.olMailItem);
                mailItem.Subject = "This is the subject";
                mailItem.To = "someone@example.com";
                mailItem.Body = "This is the message.";
                mailItem.Importance = Outlook.OlImportance.olImportanceLow;
                mailItem.Display(false);
            }
            catch (Exception)
            {

                throw;
            }           
        }

I get error on the very first line, var outlookApp = new Outlook.Application();

The exception says:

{"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))."}

The code works fine when executed from a console application, but not when it is executed from an application page which resides in the 15 hive.

I am using Outlook 2010, and v 14 of Microsoft.Office.Interop.Outlook, in a SharePoint 2013 on-prem environment.

  • 1
    Is Outlook installed on your SharePoint 2013 server? If yes then have you included that dll – Asad Refai Aug 21 '15 at 9:34
  • Yes, Outlook is installed on the SharePoint 2013 server, and the code works and an outlook window pops up if I run the same code in a console application instead of running it from an application page from SharePoint. – Ilyas Aug 21 '15 at 11:21
  • Check this if it's helpful in any way stackoverflow.com/questions/3477086/… – Asad Refai Aug 21 '15 at 11:31
  • This is more of a C# question than a SharePoint one. Should be in SO imo. – Akhoy Aug 21 '15 at 11:48
  • No. Not really. The c# code executes fine, but not from SharePoint. That is why it is relevant, and why I am asking here. – Ilyas Aug 21 '15 at 12:09
1

There are few things we need to check.

  1. Is Outlook installed on your SharePoint 2013 server?

  2. If yes then, have you referenced it?

Ways to reference the dll which is to be used in Application Page or else where

Best Practice: If you are making a deployment .wsp for your project then place this dll in your package.

  1. Open up your SharePoint Project in Visual Studio, and double click on Package.
  2. Package.package will open up, click on Advanced tab
  3. Under Additional Assemblies add a new one, in your case the Outlook.interop
  4. Build the project and deploy.

Refer the below screenshot

enter image description here

And other way which I do not consider a best way, but you can try while in development environment

  1. Go to InetPub folder on your server, where the virtual directory of your site created.
  2. Locate your Virtual Directory, and find Bin folder inside it
  3. Place the dll in the Bin folder, then check again your application page.
  • Hi, and thanks for your answer. I added the .dll in package, and have Outlook installed on the server I am testing on. Still I get this 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)). – Ilyas Aug 21 '15 at 11:19
0

I have two ideas:

  1. Have to tried to run he run with ElevatedPrivileges?
  2. Could you try to give the IIS Application Pool Accounts permisions on the directory where the original .dll resides and see what happens

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.