我使用VS2010,C#,ASP.NET來閱讀Outlook電子郵件。我設置的Outlook Express 6我的Gmail(IMAP),我會在第一線,對創建我的COM對象一個奇怪的例外,這裏是我的代碼:在ASP.NET中使用MAPI時使用MAPI的錯誤
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應用程序中沒有運氣
謝謝親愛的SilverNinja,我測試了它,但是應該爲每個用戶執行此過程嗎?事實上,我正在嘗試編寫一個可由我的Silverlight應用程序訪問的WCF,它將用於閱讀電子郵件,目前我直接閱讀IMAP,但也應該添加Outlook,我應該在哪裏更改這些設置?僅在我的服務器上? –
這隻會在服務器上完成,無論哪個帳戶正在運行應用程序池。對於IIS 6,它將是IIS_IUSRS,但對於IIS 7,則需要在應用程序池設置中進行配置。 – SliverNinja