我使用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;
}
这是我的异常(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)).
此异常是在第一行创建的:
app = new Microsoft.Office.Interop.Outlook.Application();
我使用了 Microsoft.Office.Interop.Outlook.dll
文件作为互操作引用,这里出了什么问题?我可以在 Outlook Express 6 中阅读 Gmail 收件箱,但在 ASP.NET Web 应用程序中却无法阅读
最佳答案
尝试配置 appropriate COM Activation permissions让 Office 应用程序在 ASP.NET 下运行。
关于asp.net - 在 ASP.NET 中使用 MAPI 读取 oulook 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11031676/