EWS to MS Graph notification

Pacelli, Joe 1 Reputation point
2021-09-20T13:46:00.65+00:00

So I currently have a windows service implementation which is using EWS. This windows service uses the streaming subscription and opens a connection and a cron schedule to periodically check if the connection is still alive, if not re-establish this connection.
There are 3 event handlers
OnNotification
OnError
OnDisconnect

This windows service is monitoring a service email account for new emails and when received checks if they conform to a certain format and if so the service will call a webservice to process this email.

I've read that EWS will eventually be decommissioned and to switch to MS Graph
So I've been starting to read about MS Graph and want to know;
How easy can I swap out the EWS Streaming Subscription over to the Graph API?
Also, what are the requirements?
Currently we are using VS 2017, so it either needs to remain in .Net Framework 4.7, or .Net Core 2.1.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,557 questions
Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
506 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. David Barrett 6 Reputation points Microsoft Employee
    2021-09-21T13:20:04.197+00:00

    There are currently no plans to decommission EWS. The Graph equivalent for subscriptions is webhooks: https://learn.microsoft.com/en-us/graph/api/resources/webhooks?view=graph-rest-1.0.

    1 person found this answer helpful.
    0 comments No comments

  2. Pacelli, Joe 1 Reputation point
    2021-09-22T19:37:23.843+00:00

    So I was able to create an ASP.NET Core Web API which will run as a windows service and it successfully creates the subscription. But when I test the notification I get 20 notifications for a single email message. What we have is an approval process that sends out an email to an individual and within this email they can select Approve or Deny. This will send an email to our email queue. Something like svc_EmailQueue@mathieu.company .com
    This is the account used to get the access token and create the subscription
    string postBody = String.Format(@"resource=https%3A%2F%2Fgraph.microsoft.com%2F&client_id={0}&client_secret={2}&grant_type=password&username=svc_EmailQueue@mathieu.company .com&password={1}&scope=Mail.Read", config.ClientID, config.Password, config.ClientSecret);

    And I used the following for the subscription
    var sub = new Microsoft.Graph.Subscription();
    sub.ChangeType = "updated";
    sub.NotificationUrl = config.NotificationURL + "/api/notifications";
    sub.Resource = "/me/messages";
    sub.ExpirationDateTime = DateTime.UtcNow.AddMinutes(15);
    sub.ClientState = "SecretClientState";

    So once it was created I took one of the emails and Denied the approval which sent the email to svc_EmailQueue@mathieu.company .com.
    I then saw 20 POST notifications.
    I only want the single notification that I received the email so we can process it and determine the next step.

    Why am I getting some many notifications for a single email received?
    Do I need to track the ID of the notification and just process the first occurence?

    0 comments No comments

  3. David Barrett 6 Reputation points Microsoft Employee
    2021-09-23T07:35:10.613+00:00

    You will get a notification on every change (i.e. whenever any property on the object changes). Multiple changes can trigger multiple events. It is up to the client to process the ones that are interesting to it. If you use EWS subscriptions you could use the NewMail event, which would only occur on new mail.