The above said task seems so simple as per this stack overflow question or this MSDN How To.
But I am just struck at the line foreach (Outlook.MailItem mail in items), where I get an exception saying “Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘Microsoft.Office.Interop.Outlook.MailItem’ …”.
Though there are quite a few posts about this exception, none could help me in getting over it.
Can someone please help me to solve this and to be able to read the emails from C#.
Thanks
Not every item in an Outlook Explorer is necessarily a
MailItem. For example, public folders containPostItems. If I remember correctly, conflict messages and meetings request also have their own item type.Thus, I would design the loop as follows: