I'm trying to list all folders (in order to later on get messages from one specific folder) using the Microsoft Office Interops.
If I run this code with storeIdx
set to 1 (which is my personal mailbox) it works great, but if I try running this on storeIdx
2 (which is a shared mailbox I also use) it returns absolutely nothing:
private void ProcessMail()
{
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
_NameSpace ns = app.GetNamespace("MAPI");
int storeIdx = 2;
MAPIFolder inbox = ns.Stores[storeIdx].GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Console.WriteLine("Getting folders from mailbox: " + ns.Stores[storeIdx].DisplayName + " in folder " + inbox.Name +"\r\n");
Console.WriteLine("FOLDERS:\r\n");
foreach (MAPIFolder f in inbox.Folders)
{
Console.WriteLine(f.Name + " (" + f.FullFolderPath + ")");
}
}
I've tried a couple of different things after reading on various sites (MSDN among others) but it simply won't show me any subfolders in the inbox of the shared mailbox. In Outlook I'm able to see them just fine and work with them.
The mailboxes are all on the same Exchange server.
Any help would be appreciated.