question

PacelliJoe-8167 avatar image
0 Votes"
PacelliJoe-8167 asked PacelliJoe-8167 commented

EWS to MS Graph notification

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.

office-exchange-server-devmicrosoft-graph-notificationsmicrosoft-graph-change-notifications
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

David-Barrett avatar image
1 Vote"
David-Barrett answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PacelliJoe-8167 avatar image
0 Votes"
PacelliJoe-8167 answered

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@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@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@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?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

David-Barrett avatar image
0 Votes"
David-Barrett answered PacelliJoe-8167 commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

So what is the equivalent of NewMail event from EWS Subscriptions within MS Graph?
This is what I'm currently doing in our windows service. It currently connects to EWS and subscribes to notifications and it's working fine
It checks the connection and re-connects ever 30 minutes since this is the maxmium amount of time.

But I'm looking to move this windows service from EWS to MS Graph
I did make changes to the create subscription
sub.ChangeType = "created";
sub.Resource = "/me/mailFolders('Inbox')/messages";
I'm looking at created and just the Inbox
I only received 2 notifications. I plan to retrieve the 2 messages and see if there is any difference
Some other condition I can use when triggering my notification

0 Votes 0 ·