我能够从我的outlook根文件夹中提取邮件的主题。
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“文件夹的子文件夹时,它会给出一条错误消息。
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);
}错误信息是:
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我做错什么了?请帮我,谢谢。
发布于 2018-06-27 02:52:29
假设文件夹中只有MailItem对象。您还可以拥有ReportItem或MeetingItem对象。将循环更改为
foreach (object item in test_folder.Items)
{
Outlook.MailItem mItem = item as Outlook.MailItem;
if (mItem != null)
{
...https://stackoverflow.com/questions/51053855
复制相似问题