如下代码 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等等...
谢谢..