Skip to content
Demo using an Azure Function to intercept mailgun webhooks
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

MailGun Webhook email alerts with Azure Functions

Use an Azure function to intercept your MailGun webhooks.


  • HandleWebhook receives any webhook from MailGun, then invokes the appropriate response strategy based on the MailGunEvent type. For example, it might add outgoing alert email messages to the 'email-outbox' storage queue.
  • DrainOutbox processes the 'email-outbox' queue, sending queued emails via the SendGrid API.


MailGun POCOs!

The request body payload is deserialized to C# classes to make working with the data easier and more type-safe.

Why SendGrid for the email alerts?

  1. If MailGun is having issues, it might make sense to send the alerts via another channel
  2. SendGrid is easier to work with in Azure. There's a nuget package and everything. :)

Getting Started

  1. Clone the repo. :)
  2. Create local.settings.json in the root of the repo and set it up like this:
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "alert-email-addresses": "{ This email addresses to alert, separated by semicolons ';' }",
    "from-email-address": "{ Your email address }",    
    "mailgun-webhook-signing-key": "{ Get this from }",
    "sendgrid-api-key": "{ Your API key for SendGrid }"
  1. Run the project in Visual Studio (not Visual Studio Code if you want the full development experience)
  2. Run ngrok and point it against your visual studio dev server
  3. Head over to the mailgun webhooks page for your site, for example From there you can paste in your URL and see what happens. As coded, the URL might look something like
  4. Create new implementations of IResponseStrategy to customize all the response things.

Have fun. 😊

You can’t perform that action at this time.