Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7398605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:53:26+00:00 2026-05-29T03:53:26+00:00

The above said task seems so simple as per this stack overflow question or

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:53:27+00:00Added an answer on May 29, 2026 at 3:53 am

    Not every item in an Outlook Explorer is necessarily a MailItem. For example, public folders contain PostItems. If I remember correctly, conflict messages and meetings request also have their own item type.

    Thus, I would design the loop as follows:

    foreach (object item in items) {
        var mail = item as MailItem;
        if (mail != null) {
            // do something useful
            ...
        } else {
            // log or show some message box, so that you can debug this case
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempted translation of the above question from non-native English to English: This is a
The above error message comes up just before SQL Server marks the database as
The above expression is working fine. this expression means first leter should start with
As said above For instance WHERE In(var 1,var 2,var 3, ..., var 5609,) Any
As I said above, I want to know what are all the disadvantage of
This is the page that I'm having. But the resize part in the section
See above. I need to move my bitmaps around a Form, or perhaps inside
In Java 5 and above you have the foreach loop, which works magically on
The image above is from Wikipedia's entry on AVL trees which Wikipedia indicates is
I encountered the above error message after applying the OutputCache attribute on ActionResult methods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.