首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从outlook的子文件夹中提取邮件主题?

如何从outlook的子文件夹中提取邮件主题?
EN

Stack Overflow用户
提问于 2018-06-27 02:47:19
回答 1查看 43关注 0票数 0

我能够从我的outlook根文件夹中提取邮件的主题。

代码语言:javascript
复制
Outlook.Application test_app = new Outlook.Application();
Outlook.NameSpace test_space = test_app.GetNamespace("MAPI");
Outlook.MAPIFolder test_folder = test_space.Folders["TanRong.Loo@infineon.com"].Folders["Test"];
foreach (Outlook.MailItem items in test_folder.Items)
{
    Console.WriteLine(items.Subject);
}

但是,当我试图访问根"Test“文件夹的子文件夹时,它会给出一条错误消息。

代码语言:javascript
复制
Outlook.Application test_app = new Outlook.Application();
Outlook.NameSpace test_space = test_app.GetNamespace("MAPI");
Outlook.MAPIFolder test_folder = test_space.Folders["TanRong.Loo@infineon.com"].Folders["Test"].Folders["Test1"];
foreach (Outlook.MailItem items in test_folder.Items)
{
    Console.WriteLine(items.Subject);
}

错误信息是:

代码语言:javascript
复制
Unhandled Exception: System.InvalidCastException: 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)).
at outlook_to_excel.Program.Main(String[] args) in C:\Users\LooTanRo\Desktop\Outlook Export\CS\outlook_to_excel\outlook_to_excel\Program.cs:line 51

我做错什么了?请帮我,谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-27 02:52:29

假设文件夹中只有MailItem对象。您还可以拥有ReportItemMeetingItem对象。将循环更改为

代码语言:javascript
复制
foreach (object item in test_folder.Items)
{
  Outlook.MailItem mItem = item as Outlook.MailItem;
  if (mItem != null) 
  {
     ...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51053855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档