【发布时间】:2011-06-07 01:57:24
【问题描述】:
我已经编写了这段代码来查看我的 Outlook 邮箱中的未读项目,代码如下:
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 循环中我收到此错误:
“无法将类型为“System.__ComObject”的 COM 对象转换为接口类型“Microsoft.Office.Interop.Outlook.MailItem”。此操作失败,因为对具有 IID 的接口的 COM 组件调用 QueryInterface '{00063034 -0000-0000-C000-000000000046}' 由于以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE))。”
您能帮我解决这个错误吗?
【问题讨论】:
-
@Bolu 不,这是我在 c# Windows 应用程序中写的内容
-
MAPIFolder 已弃用,请改用 Folder。
-
你解决这个问题了吗?
-
此错误与更改Office版本一致。 (它会产生一系列问题)需要做的是编辑一些注册表文件,如下所述:stackoverflow.com/questions/12957595/…
标签: c# outlook c#-2.0 office-interop outlook-2003