我寫了這個代碼來查看我的Outlook郵箱中的未讀項目,這裏是代碼:無法投COM對象 - 微軟Outlook和C#
Microsoft.Office.Interop.Outlook.Application app;
Microsoft.Office.Interop.Outlook.Items items;
Microsoft.Office.Interop.Outlook.NameSpace ns;
Microsoft.Office.Interop.Outlook.MAPIFolder inbox;
Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
app = application;
ns = application.Session;
inbox = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
items = inbox.Items;
foreach (Microsoft.Office.Interop.Outlook.MailItem mail in items)
{
if (mail.UnRead == true)
{
MessageBox.Show(mail.Subject.ToString());
}
}
但foreach循環我得到這個錯誤:
"Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
你能幫我解決這個錯誤嗎?
這是一個加載項? – Bolu 2011-01-11 10:10:23
@Bolu不,這是我寫在我的C#Windows應用程序 – Zerotoinfinity 2011-01-11 10:23:01
MAPIFolder已棄用,請使用文件夾。 – 2011-01-11 10:29:38