How to get unread mail from a specific folder

I use the code below to check unread mail from Outlook and everything works fine for the default inbox

Microsoft.Office.Interop.Outlook.Application oApp; Microsoft.Office.Interop.Outlook._NameSpace oNS; Microsoft.Office.Interop.Outlook.MAPIFolder oFolder; Microsoft.Office.Interop.Outlook._Explorer oExp; oApp = new Microsoft.Office.Interop.Outlook.Application(); oNS = (Microsoft.Office.Interop.Outlook._NameSpace)oApp.GetNamespace("MAPI"); oFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); oExp = oFolder.GetExplorer(false); oNS.Logon(Missing.Value, Missing.Value, false, true); Microsoft.Office.Interop.Outlook.Items items = oFolder.Items; foreach (Object mail in items) { if ((mail as Microsoft.Office.Interop.Outlook.MailItem) != null && (mail as Microsoft.Office.Interop.Outlook.MailItem).UnRead == true) { string sasd= (mail as OutLook.MailItem).Subject.ToString(); } } 

But I want to check another folder [which I created [Name = "Inbox_Personal"]]. How can i do this?

Change 1

Any suggestion or link to the tutorial will be appreciated.

+4
source share
2 answers
 var fld = (Outlook.Folder)app.Session.GetFolderFromID("Inbox_Personal", storeID); 

I can’t remember where to get the store identifier, but must be stored in your session object of another default folder object.

EDIT Now I looked at the project: StoreID in GetFolderFromID is optional (Type.Missing).

The default repository identifier can be found here:

 app.Session.DefaultStore.StoreID 

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook._namespace.defaultstore(v=office.12).aspx

0
source

I use something similar to the following to access other accounts in Outlook (2007 and above, there are no stores until 2007, and you just need to look at the folders)

 Microsoft.Office.Interop.Outlook.Application oApp; Microsoft.Office.Interop.Outlook.NameSapce oNS = oApp.GetNameSpace("Mapi"); foreach(Microsoft.Office.Interop.Outlook.Store oAccounts in oNS.Stores) { // get the right account: Microsoft.Office.Interop.Outlook.Store oDesiredAccount; foreach(Microsoft.Office.Interop.Outlook.Store oAccount in oAccounts) { if(oAccount.DisplayName.ToLower.Equals("<<Name of Account>>") { oDesiredAccount = oAccount; } } // do stuff with the account Microsoft.Office.Interop.Outlook.MAPIFolder root = oAccount.GetRootFolder(); // .... } 
+3
source

All Articles