2

我使用 VS2010、C#、ASP.NET 来阅读 Outlook 电子邮件。我已经用我的 gmail (IMAP) 设置了 Outlook Express 6,我在第一行遇到了一个奇怪的异常,我的 COM 对象正在这里创建,这是我的代码:

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;
}

这是我的例外:

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

在第一行创建此异常:

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

我使用Microsoft.Office.Interop.Outlook.dll文件作为互操作参考,这里出了什么问题?我可以在 Outlook Express 6 中阅读我的 Gmail 收件箱,但在我的 ASP.NET Web 应用程序中没有运气

4

2 回答 2

2

尝试为 Office 应用配置适当的 COM 激活权限以在 ASP.NET 下运行。

于 2012-06-14T13:41:12.787 回答
0

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.

于 2012-06-14T17:58:16.443 回答