When I execute below code in console application it gives the accurate result but when I try it in windows form it throws COM exception on Outlook.Application app = new Outlook.Application();
The Exception is "Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))."
if (comboBoxFolder.SelectedIndex == 0)
{
setInboxView();
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace outlookNs = app.GetNamespace("MAPI");
Outlook.MAPIFolder emailFolder = outlookNs.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
foreach (Outlook.MailItem item in emailFolder.Items)
{
mails[0] = item.SenderEmailAddress;
mails[1] = item.To;
mails[2] = item.Subject;
mails[3] = Convert.ToString(item.ReceivedTime);
}