Getting mail information from out look inbox RRS feed

  • Question

  • Hi  All ,


    I am creating a small utility which will read information from my outlook (2010) inbox and inserted to sql server.

    i am using the following code



      Microsoft.Office.Interop.Outlook._Application olApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();

                    Microsoft.Office.Interop.Outlook._NameSpace olNS = olApp.GetNamespace("MAPI");

                    Microsoft.Office.Interop.Outlook.MAPIFolder oFolder = olNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);





    foreach( Microsoft.Office.Interop.Outlook._MailItem mit in oFolder.Items)



                                obj.Add(new MailData() { Email = mit.SenderEmailAddress, Subject = mit.Subject });


    It is getting information from inbox if the item is MailItem only else (in case of read report or delivery report  ) it is throwing casting error. 

    "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))."


    please help me to find a solution.



    Thank you,

    RP Daniel



    Riju Parayidayil
    • Edited by RPDaniel Friday, May 27, 2011 9:58 AM
    Friday, May 27, 2011 8:59 AM

All replies

  • Hello,

    A raw sketch:

    foreach( object item in oFolder.Items)


       Microsoft.Office.Interop.Outlook._MailItem mit = item as Microsoft.Office.Interop.Outlook._MailItem;

       if (mit != null)


        ... your functionality

    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Friday, May 27, 2011 9:54 AM
  • Hello Andrei,

    This will solve that exception but , i need information form all inbox items like Read Report,delete report, delivery report also, i am using the following code for getting information from my inbox 


                        IEnumerator ir = items.GetEnumerator();

                        for (int i = 1; i < oFolder.Items.Count; i++)


                            if (ir.Current is Microsoft.Office.Interop.Outlook.MailItem)


                                Microsoft.Office.Interop.Outlook.MailItem mit = (Microsoft.Office.Interop.Outlook.MailItem)ir.Current;

                                obj.Add(new MailData() { Email = mit.SenderEmailAddress, Subject = mit.Subject });


                            else if (ir.Current is Microsoft.Office.Interop.Outlook.MeetingItem)


                                Microsoft.Office.Interop.Outlook.MeetingItem mit = (Microsoft.Office.Interop.Outlook.MeetingItem)ir.Current;

                                obj.Add(new MailData() { Email = mit.SenderEmailAddress, Subject = mit.Subject });



                                if (ir.Current is Microsoft.Office.Interop.Outlook.ReportItem)


                                    Microsoft.Office.Interop.Outlook.ReportItem mit = (Microsoft.Office.Interop.Outlook.ReportItem)ir.Current;

                                    obj.Add(new MailData() { Email = "Report", Subject = mit.Subject });






    but this report item is not giving the sender email address, and also i want to copy these items to a user folder  



    RP Daniel.


    Riju Parayidayil
    Monday, May 30, 2011 5:36 AM
  • can u please tell how to get sender email id from a report item ?
    Riju Parayidayil
    Monday, May 30, 2011 10:10 AM