Using Graph API, How to get notification when user received a new mail?

sne 0 Reputation points
2023-03-20T11:01:04.52+00:00

Hi,

My question is how to get notification when new mail is received using a Graph API. I'm using c# in console app. I went through documentation. but didn't get it much. exactly what I need to do?

Could anyone help me with steps or any sample code?

Thanks

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,792 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-03-20T12:45:09.9633333+00:00

    Hello Sneha Zagade.

    Thanks for reaching out!

    Using Microsoft Graph API, to get notifications when new mail is received, you can use subscriptions. A subscription allows a client app to receive change notifications about changes to data in Microsoft Graph. Please refer to the documentation for more details.

    You can create subscription to receive notifications of mails using the below sample endpoint:

    POST https://graph.microsoft.com/v1.0/subscriptions
    Content-type: application/json
    
    {
       "changeType": "created",
       "notificationUrl": "https://webhook.azurewebsites.net/api/send/myNotifyClient",
       "resource": "me/messages",
       "expirationDateTime":"2016-11-20T18:23:45.9356913Z",
       "clientState": "secretClientValue",
       "latestSupportedTlsVersion": "v1_2"
    }
    

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.