Exchange 2013 (edit)
Exchange 2013 introduced a new affinity model which means that streaming subscriptions to multiple mailboxes need to be handled in a different way to earlier versions. If you are connecting to a single mailbox, you shouldn’t have a problem, but you most likely will encounter issues if you are connecting to many mailboxes. Additionally, the EWS managed API has not yet been updated with the changes, so quite a lot of the process needs to be implemented manually.
The steps needed to connect and monitor multiple mailboxes are as follows (please see http://msdn.microsoft.com/en-us/library/office/dn458789(v=exchg.150).aspx ):
- Call Autodiscover for each mailbox requesting the ExternalEwsUrl and a new setting called “GroupingInformation” (mailbox1, mailbox2, mailbox3, etc.)
- Group the mailboxes by a concatenation of ExternalEwsUrl + GroupingInformation
- For each group (with ~ 200 mailboxes each)
- Create the ExchangeService object (so any cookie is sent in the following requests
- Add a header to this request called “X-AnchorMailbox” with a value set the SMTP address of the first mailbox in the group
- Add a header to this request called “X-PreferServerAffinity” with a value set to “true”
- Send a Subscribe request for each mailbox in this group to get a SubscriptionId (using ApplicationImpersonation)
- Send a GetStreamingEvents request with all the SubscriptionIds from the above step (not using ApplicationImpersonation)
- Pass events returned by GetStreamingEvents or GetEvents to a separate thread for processing
I have published a code sample to Codeplex (http://ewsstreaming.codeplex.com/) that implements the above logic using the EWS Managed API. For further updates, please follow the Codeplex pages – they will be updated as the sample is improved.
EWS Streaming Notification Sample
This project demonstrates how to handle streaming notifications specifically for Wave 15 of Office 365 (and also Exchange 2013 on-premises installations). The code has recently been rewritten completely to simplify the grouping logic and add some error handling (disconnect events are handled properly, though currently subscription errors are not handled).
https://archive.codeplex.com/?p=ewsstreaming
Sample application demonstrating how to create a daemon application that interacts with EXO using EWS
https://github.com/developermessaging/EWSDaemonOAuthSample
An old code sample illustrating the use of SimpleMAPI
https://github.com/developermessaging/SimpleMAPISample
Azure Cloud
https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Client-Applications
https://docs.microsoft.com/en-us/graph/overview
https://docs.microsoft.com/en-us/graph/whats-new-overview
https://docs.microsoft.com/en-us/graph/security-authorization
https://docs.microsoft.com/en-us/mem/intune/developer/intune-graph-apis
https://docs.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-windows-desktop
https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-desktop-app-registration
Async & Await
The async/await keywords
https://www.ryadel.com/en/asyncutil-c-helper-class-async-method-sync-result-wait/
https://markheath.net/post/async-antipatterns
https://cpratt.co/async-tips-tricks/
ASP.NET Web API + Ajax Sync and Ajax Async
Secure Password
https://www.sqlshack.com/how-to-secure-your-passwords-with-powershell/
https://www.tutorialspoint.com/explain-secure-password-encryption-with-powershell
Auto Tasks
https://www.howtogeek.com/125045/how-to-easily-send-emails-from-the-windows-task-scheduler/
https://www.howtogeek.com/408827/how-to-schedule-an-email-in-outlook/