首页 新闻 会员 周边

c# Com 调用Outlook 遍历收件夹项目类型问题

0
[已关闭问题] 关闭于 2017-08-17 14:54

如下代码 C# 利用Com调用Outlook遍历收件夹中邮件时,

         Outlook.Application app = new Outlook.Application();
                Outlook.NameSpace outlookNameSpace = app.GetNamespace("MAPI");
                Outlook.MAPIFolder inbox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                Outlook.Items inBoxItems = inbox.Items;

                foreach (Outlook._MailItem m in inBoxItems)
                {
                    //deal with this item
                }

如果是邮件,则可以正常处理。

但是今天遇到一个邮件是outlook的report邮件(即outlook提示收件人不存在的邮件),

这样就在foreach遍历那边提示如下异常。

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)).

请问我在遍历收件夹时,该如何识别项目的类型?例如是MailItem、ReportItem、NoteItem等等...

谢谢..

站在那看风景的主页 站在那看风景 | 菜鸟二级 | 园豆:371
提问于:2017-07-24 10:53
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册