0
votes

In my inbox there are some calendar mail (meeting request from calendar). when application are fetching mail of calendar mail from inbox then it is throwing following 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)).

public void GetOutLookEmails()
{ 
      oApp = new Outlook.Application();
      oNS = oApp.GetNamespace("MAPI");

      foreach (Outlook.MAPIFolder folder in oNS.Folders)
      {
          GetFolders(folder);
      }
}

public void GetFolders(Outlook.MAPIFolder folder)
{
    if (folder.Folders.Count == 0)
    {
        try
        {
            if (folder.DefaultItemType == Outlook.OlItemType.olMailItem)
            {
                if (folder.Name == "Inbox")
                {
                    oEmailsFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                    Outlook.Items Inboxitems = oEmailsFolder.Items;

                    if (Inboxitems.Count > 0)
                    {
                        foreach (Outlook.MailItem mail in Inboxitems)///when compiler comes here it does not create mail object and throws error...because email contains calendar reminder so I guess I need to check if it is olCalendar event or something else that resolves error

                        {
                            if (mail != null)
                            {
                                 //here I am retrieving concerning data from emails///no issue here
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    else
    {
        foreach (Outlook.MAPIFolder subFolder in folder.Folders)
        {
            GetFolders(subFolder);
        }
    }
}
1
It would help if you could post some code :). - Florian F.
are you using exchange web services? - Lars Anundskås
seems like the COM reference you are using is NOT registered on that machine. - Ahmed ilyas
no actualy i am importing outlook emails into my project based on C# usualy emails are being imported successfuly if there is no emails coresponding to any calender reminder...but when email that belongs to any calander reminder the (Outlook.MailItem mail in Inboxitems) gives eror.. - RameezAli
ok Ahmed ilyas kindly guide me how to register COM reference... - RameezAli

1 Answers

0
votes

The item which you are casting may be of different type - ContactItem, AppointmentItem, MeetingItem, TaskItem. Check for the type and then cast it and use it.

https://msdn.microsoft.com/en-us/library/ms268994.aspx

-Vimal