Question

I use VS2010, C#, ASP.NET to read outlook email. I've setup outlook express 6 with my gmail (IMAP), I get a strange exception at the first line, where my COM object is being created, here is my code:

Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;
Microsoft.Office.Interop.Outlook.PostItem item = null;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;

try
{
    app = new Microsoft.Office.Interop.Outlook.Application();
    ns = app.GetNamespace("MAPI");
    ns.Logon("gmail_id", "gmail_pass", false, true);

    inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
    subFolder = inboxFolder.Folders["MySubFolderName"]; //folder.Folders[1]; also works
    Console.WriteLine("Folder Name: {0}, EntryId: {1}", subFolder.Name, subFolder.EntryID);
    Console.WriteLine("Num Items: {0}", subFolder.Items.Count.ToString());

    for (int i = 1; i <= subFolder.Items.Count; i++)
    {
        item = (Microsoft.Office.Interop.Outlook.PostItem)subFolder.Items[i];
        Console.WriteLine("Item: {0}", i.ToString());
        Console.WriteLine("Subject: {0}", item.Subject);
        Console.WriteLine("Sent: {0} {1}", item.SentOn.ToLongDateString(), item.SentOn.ToLongTimeString());
        Console.WriteLine("Categories: {0}", item.Categories);
        Console.WriteLine("Body: {0}", item.Body);
        Console.WriteLine("HTMLBody: {0}", item.HTMLBody);
    }
}
catch (System.Runtime.InteropServices.COMException ex)
{

}
finally
{
    ns = null;
    app = null;
    inboxFolder = null;
}

it is my exception:

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)).

this exception is create at the first line:

app = new Microsoft.Office.Interop.Outlook.Application();

I've used Microsoft.Office.Interop.Outlook.dll file as my interop reference, what is going wrong here? I can read my Gmail inbox in outlook express 6, but I have no luck in my ASP.NET web app

Was it helpful?

Solution

Try configuring the appropriate COM Activation permissions for Office apps to run under ASP.NET.

OTHER TIPS

Firstly, you should not ever use any Office app (Outlook included) in a service (such as IIS). No exceptions, it is simply not supported. Secondly, if you are using the Outlook Object Model (not in a service), you need to have Outlook (the real one) intalled. OE has nothing in common witt Outlook 2010/2007/2003/etc., except for the word "Outlook" in the name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top