You are already implicitly casting each item in
programobj.folder.Items
to the
Outlook.MailItem
type in the foreach loop header (
foreach (Outlook.MailItem mailitem in...)
).
Try this:
foreach (object item in programobj.folder.Items)
{
try
{
if (item is Outlook.MailItem)
{
Outlook.MailItem mailitem = (Outlook.MailItem)item;
}
}
catch(exception e)
{
}
Regards,
Thomas.