Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Outlook.MailItem Issues

Outlook.MailItem Issues

Scheduled Pinned Locked Moved C#
comtoolshelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sun Rays
    wrote on last edited by
    #1

    Hello All, I want to read all mail of one folder from outlook and here is code at which line i am getting error....

    Outlook.Items MailItems;

    MailItems = .......

    for (int i = MailItems.Count; i >= 1; i += -1)
    {
    Outlook.MailItem mitem;
    mitem = (Outlook.MailItem)MailItems.Item(i); //// I AM GETTING error here....
    }

    When casting getting below exception.. Tried lot from Google and other sites not getting appropriate solution. 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))."

    Thanks, Sun Rays To get something you must have to try once. My Articles

    D 1 Reply Last reply
    0
    • S Sun Rays

      Hello All, I want to read all mail of one folder from outlook and here is code at which line i am getting error....

      Outlook.Items MailItems;

      MailItems = .......

      for (int i = MailItems.Count; i >= 1; i += -1)
      {
      Outlook.MailItem mitem;
      mitem = (Outlook.MailItem)MailItems.Item(i); //// I AM GETTING error here....
      }

      When casting getting below exception.. Tried lot from Google and other sites not getting appropriate solution. 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))."

      Thanks, Sun Rays To get something you must have to try once. My Articles

      D Offline
      D Offline
      dennissal
      wrote on last edited by
      #2

      Were you able to figure this out? I am having the smae problem on undeliverable emails that are bounced back to the inbox. thanks dennis

      E 1 Reply Last reply
      0
      • D dennissal

        Were you able to figure this out? I am having the smae problem on undeliverable emails that are bounced back to the inbox. thanks dennis

        E Offline
        E Offline
        Ed Arnone
        wrote on last edited by
        #3

        The below section should assist anyone attempting to use the MailItem object. The key to this code not throwing exceptions is that the items collection may contain more than just MailItems and therefore the following code allows you to retrieve just the MailItems from the collection.

        //create an instance of Outlook
        Outlook.Application olApp = new Outlook.Application();
        //create a MAPIFolder object pointed to the default inbox
        Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)olApp.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
        //create an Items collection and pass in the inbox items
        Outlook.Items Inboxitems = inBox.Items;

        //loop through the items that are MailItem and collect the size of the items
        //to get the total size of the inbox
        foreach (Outlook.MailItem item in Inboxitems.OfType())
        {
        InboxSize = InboxSize + item.Size;
        }

        Obviously once you have a handle to the individual Mailitem you can access all of it's properties. Happy Coding :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups