Open outlook in ASP.Net

2.8k Views Asked by At

I have an ASP.net application that would open an outlook on a certain function. sample code:

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
        Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
        oNS.Logon(null, null, true, true);

        Microsoft.Office.Interop.Outlook.MailItem oMail = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
        oMail.Subject = "Sample Subject";
        oMail.To = "[email protected]";
        oMail.HTMLBody = "Sample Paragraph";
        oMail.Display(false);

        oApp = null;
        oNS = null;
        oMail = null;

This is working just fine when I run it through Visual Studio. After that I publish it to IIS 5.1 so basically i'm using windows xp machine.

Now I've run it using the published version on IIS, and i got the error "Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046}".

I've fixed it by putting an impersonation on the web.config file. Now the application is running successfully without error.

But the problem now is it doesn't seem to open the outlook, I've tried debugging it via attach to process on aspnet_wp.exe and was able to attach to a break point and it seemed to pass through all the lines without throwing an error but i just doesn't open the outlook.

Am I missing something to configure on the IIS level? Thanks!

1

There are 1 best solutions below

1
On

Try running the web app's application pool under a user that has access permissions. or even you can try to restart the iis and try out. it basically causing because of security issues concenrend. when i googled this issue, i got this Aspnet Security contexts

suggestions may help to solve problem.

  1. Enter identity credentials in webconfig or in iis
  2. Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files give write permissions.