Unable to cast COM object – Microsoft outlook & C#

I had to get around something like your problem a while back.

        foreach (Object _obj in _explorer.CurrentFolder.Items)
        {
            if (_obj is MailItem)
            {
                 MyMailHandler((MailItem)_obj);
            }
        }

Hope that helps.

The issue here is that _explorer.CurrentFolder.Items can contain more objects than just MailItem (PostItem being one of them).

Leave a Comment