I\'m trying to get number of unread emails from Exchange for specific user.
I\'m able to get number of emails from Inbox like so:
SearchFilter sf = n
Code example for fetching folders and their counts. In this example, we are listing all first-level folders, and adding them to a common class list of folders, with a NewMessageCount object in there. Key is the Folder.Bind(myService, folder.Id).UnreadCount section.
public List ListFolders()
{
try
{
List myFolders = new List();
Common.MailFolder myFolder;
List myExchangeFolders = new List();
FolderView myView = new FolderView(10);
myView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, FolderSchema.DisplayName, FolderSchema.Id);
myView.Traversal = FolderTraversal.Shallow;
FindFoldersResults myResults = myService.FindFolders(WellKnownFolderName.MsgFolderRoot, myView);
foreach (Folder folder in myResults)
{
myFolder = new Common.ICE.MailFolder();
myFolder.NewMessageCount = Folder.Bind(myService, folder.Id).UnreadCount;
myFolder.FolderId = folder.Id.ToString();
myFolder.FolderName = folder.DisplayName;
myFolders.Add(myFolder);
}
return myFolders;
}
catch (Exception ex)
{
Logger.Log.Error("Exchange Helper - List Folders", ex, Utility.GetUserId());
return null;
}
}