none
How to read mail from user defined folder in Inbox? RRS feed

  • Question

  • Environment:  -

    Exchange Server: - Exchange Server 2010 SP3

    EWS API: - 2.0

    IDE: - Visual Studio 2008

    Language: - C#

    .

    Requirement: -

    .

    We have created John folder inside Inbox Folder . Now want to read mails of John folder from EWS API. What will be the best way to read mails from there.

    .

    Kindly assist, I will be really thankful.



    Regards, S.P Singh

    Monday, August 31, 2015 9:55 AM

Answers

  • You first need to Find the Folder in order to obtain the FolderId https://msdn.microsoft.com/en-us/library/office/hh532558(v=exchg.80).aspx . Once you have the FolderId you use the FindItems operation to enumerate the Item within that folder https://msdn.microsoft.com/en-us/library/office/dn535506(v=exchg.150).aspx eg

                Folder SubFolder = FolderFromPath(service, "\\Inbox\\aa", "use@domain.com");
                FindItemsResults<Item> FindResults = null;
                ItemView itemv = new ItemView(1000);
                do
                {
                    FindResults = service.FindItems(SubFolder.Id, itemv);
                    if (FindResults.Items.Count > 0)
                    {
                        foreach (Item itItem in FindResults.Items)
                        {
                            Console.WriteLine(itItem.Subject);
                        }
                    }
                    itemv.Offset += FindResults.Items.Count;
                } while (FindResults.MoreAvailable);
    
    
    internal static Folder FolderFromPath(ExchangeService service, String FolderPath, String MailboxName)
            {
                FolderId RootFolderId = new FolderId(WellKnownFolderName.MsgFolderRoot, MailboxName);
                Folder RootFolder = Folder.Bind(service, RootFolderId);
                String[] faFldArray = FolderPath.Split('\\');
                Folder tfTargetFolder = RootFolder;
                for (int lint = 1; lint < faFldArray.Length; lint++)
                {
                    if (faFldArray[lint].Length != 0)
                    {
                        FolderView fview = new FolderView(1);
                        SearchFilter sf = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, faFldArray[lint]);
                        FindFoldersResults ffResult = service.FindFolders(tfTargetFolder.Id, sf, fview);
                        if (ffResult.TotalCount == 0)
                        {
                            throw new Exception("Folder Not Found");                        
                        }
                        else
                        {
                            tfTargetFolder = ffResult.Folders[0];
                        }
                    }
                }
                return tfTargetFolder;
            }

    Cheers
    Glen

    • Marked as answer by S.P Singh Tuesday, September 1, 2015 6:14 AM
    Tuesday, September 1, 2015 4:23 AM