Reputation: 2369
I have successfully connected to Microsoft Graph using OAuth. I can receive and send emails from my Office365 account.
But I am completely stuck on how to receive emails automatically, similar to the IMAP IDLE routine.
I am referencing
using Microsoft.Graph;
using Microsoft.Toolkit.Services.MicrosoftGraph;
I have tried Subscription but have no clue what to do next, or even if this is correct.
Subscription sub = new Subscription {
ChangeType = "created",
NotificationUrl = "urn:ietf:wg:oauth:2.0:oob",
Resource = "/users/me/messages",
ExpirationDateTime = DateTimeOffset.Now.AddMinutes(20),
ClientState = "????" // if applicable, what is this
};
Upvotes: 1
Views: 1009
Reputation: 2369
Subscriptions are not in possible at this moment using Microsoft Graph for UWP, for notifications the Outlook 365 API should be used. The Microsoft graph api can be used for Auth and other tasks though.
Can Microsoft consider including streaming notifications in Microsoft Graph?
Upvotes: 0
Reputation: 557
To make a subscription you need to expose a notification URL with https (see graph documentation).
POST https://graph.microsoft.com/v1.0/subscriptions Content-Type: application/json { "changeType": "created,updated", "notificationUrl": > "https://webhook.azurewebsites.net/notificationClient", "resource": "/me/mailfolders('inbox')/messages", "expirationDateTime": "2016-03-20T11:00:00.0000000Z", "clientState": "SecretClientState" }
If you want examples the graph documentation references a Node.js and asp.net example. Both use ngrok to expose an https URL (just for testing purposes though). The program tunnels HTTP requests through to your localhost (like a reverse proxy). If you have that setup, you have to validate your request. When you send your subscription request the first post message your notification URL will receive is a message with a validation token (see doc). You have to send this validation token back. Now you should receive notifications on your specified notification URL.
You can read about the Subscription resource type and its properties in the graph documentation. For example, the client state is described as:
Specifies the value of the
clientState
property sent by the service in each notification. The maximum length is 255 characters. The client can check that the notification came from the service by comparing the value of theclientState
property sent with the subscription with the value of theclientState
property received with each notification.
Upvotes: 4