View Single Post
  #3  
Old September 20th 08, 01:28 PM posted to microsoft.public.outlook.program_addins
[email protected]
external usenet poster
 
Posts: 24
Default Exception iterating thru inbox mailitems

On Sep 19, 8:14*pm, "Stuart Parker" wrote:
OK, The item it's failing on is a Non-Delivery Report returned by Exchange
which is in the inbox.

Is there something strange about NDRs, I assume they aren't of type mailitem
then?

"Stuart Parker" wrote in message

news
Hi


If I use a For Each to iterate through the inbox mailitems, I get the
following exception after a few items are processed:


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


What's going on ?


Cheers


Their message class is "IPM.Note.NDR", so they're a sub-type of
MailItem. I'd be surprised if it wouldn't create a MailItem from one,
but I haven't tried. Either way, when iterating through a collection,
you're always best off putting the conversion from the dispatch to the
MailItem in a try/catch. If it fails, what you have can't be used as
a MailItem.
Ads