Trigger Webhook when an email is received

Parker Wilson 30 Reputation points
2023-09-20T13:45:18.25+00:00

I am wondering if I can trigger a webhook whenever an email is received to a shared mailbox. I see there is webhooks which send a change notification whenever an email is received so I think it is possible but I am not figuring out where to do that.

Basically just when an email comes in, trigger an http call. It would also be nice if information about that email which triggered it (sender, subject, body content) was passed to the http address but that is not necessary. Currently I have a scheduled call to the graph API which gets emails from the last hour, every hour but being able to act on each email independently as it comes in would be nicer.

Thanks!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,049 questions
{count} votes

Accepted answer
  1. CarlZhao-MSFT 42,031 Reputation points
    2023-09-21T08:14:10.28+00:00

    Hi @Parker Wilson

    Of course, you can create a mail subscription and it will send a change notification when you receive a new message.

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

    Hope this helps.

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

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Oleksii Yatsenko 0 Reputation points
    2024-07-17T13:09:53.1766667+00:00

    Hey. You can alternatively use one of the services that are providing webhooks. If you still need to receive the email somewhere and also receive the webhook on it I would recommend ProxiedMail.

    Anyway, if you don't need that you can omit email forwarding and left webhook only.

    So, how it will look like once you receive the email

    Let's say you're using parker@pxdmail.com, so you can get it forwarded to

    parker@outlook.com and POST https://mywebhookdomain.com/mywebhook/url with a certain payload.

    You can find the payload example and tutorial here: https://medium.com/@yatsenkolesh/how-to-set-up-webhook-on-received-email-d59f97d5bd3d

    0 comments No comments

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.