我写了这个代码来查看我的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