Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In This Code i could to see all messages and to specify only the unread messages but my problem it show me only messages in my inbox folder main folder all sub folders are excluded

private void GetUnreadEmails4()
        {

            OutLook.Application myApp;
            myApp =new OutLook.Application();
            NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");

            
            MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

            Items oItems = myInbox.Items.Restrict("[UnRead] = true");
            //Items oItems = myInbox.Items.Restrict("[UnRead] = true");
            MessageBox.Show(oItems.Count.ToString());

            foreach (dynamic item in oItems)
            {
                try
                {
                    var oMsg = (MailItem)item;
                    listBox1.Items.Add(oMsg.Subject.ToString());
                }
                
                catch (System.Exception)

                {
                    

                }

            }
        }


What I have tried:

MAPIFolder myInbox = mapiNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

I know the problem is here but no idea please help
Posted
Updated 2-Aug-19 5:39am

1 solution

Microsoft has plenty of documentation on working with Outlook, and the folders within
Work with folders - Visual Studio | Microsoft Docs[^]

Older sample from MS, but it may be just what you need to get down to the level your are looking for
Enumerate folders | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900