Use EWS or Graph with onsite only exchange server RRS feed

  • Question

  • We have an onsite only 2016 exchange server and we currently have a web app project that gets emails from a specific folder and processes them into a database. The current code uses EWS proxy api and I was looking at bringing it up to date using the latest EWS managed API. Would it be better to use the Graph API instead? I wasn't sure if it could handle onsite only server tasks or if it was just built around Hybrid/365 projects. 
    Tuesday, October 30, 2018 12:29 PM

All replies

  • Hi Brian_A_B,

    You could get emails from a specific folder via EWS Manage API.

    Please refer to the below code:

    static void Main(string[] args)
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Credentials = new NetworkCredential("email","email_password");
                service.AutodiscoverUrl("email", RedirectionCallback);
                Folder rootfolder = Folder.Bind(service, WellKnownFolderName.Inbox);

                foreach (Folder folder in rootfolder.FindFolders(new FolderView(100)))
                    // Finds the emails in a certain folder, in this case the Junk Email
                    FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.JunkEmail, new ItemView(10));
                    // This IF limits what folder the program will seek
                    if (folder.DisplayName == "FolderName")
                        // Trust me, the ID is a pain if you want to manually copy and paste it. This stores it in a variable
                        var fid = folder.Id;
                        foreach (Item itemq in findResults.Items)
                            // Load the email, move the email into the id.  Note that MOVE needs a valid ID, which is why storing the ID in a variable works easily.


            static bool RedirectionCallback(string url)
                return url.ToLower().StartsWith("https://");


    You can’t processes them into a database via EWS Manage API.



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, October 31, 2018 7:36 AM