C# 使用C从outlook读取收件箱项目时出错#
嗨 当我试图从outlook的收件箱中读取数据时,出现以下错误 无法将“System.\u ComObject”类型的COM对象强制转换为接口类型“Microsoft.Office.Interop.Outlook.PostItem”。此操作失败,因为对IID为“{00063024-0000-0000-C000-0000000000 46}”的接口的COM组件的QueryInterface调用由于以下错误而失败:不支持此类接口(来自HRESULT的异常:0x80004002(E_NOINTERFACE)) 下面是我的C代码C# 使用C从outlook读取收件箱项目时出错#,c#,outlook,C#,Outlook,嗨 当我试图从outlook的收件箱中读取数据时,出现以下错误 无法将“System.\u ComObject”类型的COM对象强制转换为接口类型“Microsoft.Office.Interop.Outlook.PostItem”。此操作失败,因为对IID为“{00063024-0000-0000-C000-0000000000 46}”的接口的COM组件的QueryInterface调用由于以下错误而失败:不支持此类接口(来自HRESULT的异常:0x80004002(E_NOINTERFA
Microsoft.Office.Interop.Outlook.Application app=null;
Microsoft.Office.Interop.Outlook.\u命名空间ns=null;
Microsoft.Office.Interop.Outlook.PostItem项=null;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder=null;
Microsoft.Office.Interop.Outlook.MAPIFolder子文件夹=null;
尝试
{
app=新的Microsoft.Office.Interop.Outlook.Application();
ns=app.GetNamespace(“MAPI”);
ns.Logon(null,null,false,false);
inboxFolder=ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
WriteLine(“文件夹名称:{0},EntryId:{1}”,inboxFolder.Name,inboxFolder.EntryId);
WriteLine(“numitems:{0}”,inboxFolder.Items.Count.ToString());
Console.ReadLine();
对于(int i=1;i
将此部分更改为
Microsoft.Office.Interop.Outlook.MailItem item = (Microsoft.Office.Interop.Outlook.MailItem)subFolder.Items[i];
Console.WriteLine( "Item: {0}", i.ToString() );
Console.WriteLine( "Subject: {0}", item.Subject );
Console.WriteLine( "Categories: {0}", item.Categories );
Console.WriteLine( "Body: {0}", item.Body );
Console.WriteLine( "HTMLBody: {0}", item.HTMLBody );
进一步参考
您的收件箱中是否有约会等?
item = (Microsoft.Office.Interop.Outlook.PostItem)inboxFolder.Items[i];
Console.WriteLine("Item: {0}", i.ToString());
Console.WriteLine("Subject: {0}", item.Subject);
Console.WriteLine("Categories: {0}", item.Categories);
Console.WriteLine("Body: {0}", item.Body);
Console.WriteLine("HTMLBody: {0}", item.HTMLBody);
Microsoft.Office.Interop.Outlook.MailItem item = (Microsoft.Office.Interop.Outlook.MailItem)subFolder.Items[i];
Console.WriteLine( "Item: {0}", i.ToString() );
Console.WriteLine( "Subject: {0}", item.Subject );
Console.WriteLine( "Categories: {0}", item.Categories );
Console.WriteLine( "Body: {0}", item.Body );
Console.WriteLine( "HTMLBody: {0}", item.HTMLBody );