How to receive Sinch Mailgun email alerts in Discord using webhooks

Source: Transactional Email API Service For Developers | Mailgun•

How to receive Sinch Mailgun email alerts in Discord using webhooks

Picture this: Your marketing team just launched a campaign to 50,000 subscribers, but half the emails are bouncing. Your support team is wondering why customers aren't getting their password reset emails. Meanwhile, your engineering team is blissfully unaware that your transactional email system…

October 8, 2026

Email powers everything, from your checkout confirmations to your weekly newsletters, but most teams only discover problems when it’s too late. The good news? You don’t have to.

When emails bounce, get flagged as spam, or simply vanish into the digital void, every minute counts. Engineering teams need instant notifications when transactional emails fail. Support teams must know when customer communications aren’t reaching their destination. Marketing teams need real-time feedback on campaign deliverability.

The Sinch Mailgun event system can be your early warning system. Instead of checking dashboards or waiting for reports, you can pipe critical email events directly into Discord, where your team already lives.

In this tutorial, you’ll learn how to use the Sinch Mailgun webhooks feature to report on specific email events and send alerts to Discord using a Python script.

To send email alerts to Discord, you need to set up a few prerequisites beforehand.

Set up a Sinch Mailgun domain

To use Sinch Mailgun for this tutorial, you need to set up a few things on the Sinch Mailgun platform:

  • Set up a domain capable of receiving email on Sinch Mailgun. If you have a custom domain, you can set this up now and then verify your domain. On the free tier, you automatically get a sandbox domain, which is what is used in this tutorial:

Now your Sinch Mailgun system is ready to send emails, at least from the test domain.

Create a Discord webhook to receive messages

A webhook is basically an HTTP request that can be triggered by an external event, like the Python script that you’ll be running.

This example uses Discord. If you don’t have an existing Discord server, you need to create one. Once your server is up and running, you can navigate to your Server Settings to create a webhook:

Once you’ve navigated to your server settings, head on over to the Integrations tab and then click Create Webhook:

When you click Create Webhook, a new webhook is automatically created and given a name. Give the webhook a new name (anything sensible works):

Finally, click the Copy Webhook URL button. This is the URL that your Python script sends notifications to. Save this URL for later.

Now your Discord is set up and ready to receive messages from your Python script.

Create and host your Python script

There is a lot of setup involved when creating a Python script, from creating and using virtual environments to hosting your script somewhere where it can receive the data from Sinch Mailgun.

This tutorial assumes that you know how to set up and host a Python script and won’t be going into the details on how to do that. That is beyond the scope of this article.

You can either host your Python script locally and use a service like ngrok to access it from the internet, or you can host it online on a service like PythonAnywhere. PythonAnywhere, like Sinch Mailgun, also has a free tier, which should be sufficient for testing the script. There are restrictions on their free tier, especially the domains to which you are allowed to make outgoing connections from your script. Thankfully, their list of allowed domains does include URLs for Discord, so there shouldn’t be any issues.

The Python script in this tutorial is a simple Flask application, running on PythonAnywhere. Flask is a lightweight web application framework written in Python. As a bonus, PythonAnywhere supports Flask out of the box.

The application can be run as a single file called flask_app.py:

This code contains a few key functions:

  • extract_mailgun_data(request) takes the payload from Sinch Mailgun and splits it into two different parts: the signature data and the event data. This data is then passed to the other functions, where it can be used further.
  • verify_mailgun_signature(token, timestamp, signature) looks for a signing key that was sent as part of the payload from Sinch Mailgun. This is to authenticate the payload that your script receives as a payload that came from Sinch Mailgun and not another, possibly malicious, source. Read more about securing Sinch Mailgun webhooks in this documentation.
  • send_discord_alert(title, description, color=0xff0000, fields=None) is the function called by the different endpoints in your script to format and send a message to your Discord webhook. It has a default value for color, but that can be overridden later.
  • The different endpoints (or routes) are split up like this: / prints a message to the browser so that you can verify that your Flask application is up and running. /bounced handles bounced message events from Sinch Mailgun. /delivered can be used to test the entire workflow as it’s not always possible to generate a bounced or undelivered event, but it’s easy to generate a delivered one.
  • / prints a message to the browser so that you can verify that your Flask application is up and running.
  • /bounced handles bounced message events from Sinch Mailgun.
  • /delivered can be used to test the entire workflow as it’s not always possible to generate a bounced or undelivered event, but it’s easy to generate a delivered one.

You can navigate to the /test endpoint of your application directly to receive a test message on Discord without involving Sinch Mailgun. This is a great way to figure out if the Discord portion of your application is working:

Don’t forget to replace the <REPLACE_WITH_DISCORD_WEBHOOK_URL> variable with the URL you copied from Discord earlier.

Once you run your script, you should be able to navigate to the root endpoint (/) and see the Mailgun Webhook Handler is running! message. Your Flask app is now ready to receive data from Sinch Mailgun.

Set up the webhooks in Sinch Mailgun

Now that your Python script is ready to receive data and forward it onto the webhook you created in Discord, you can finally set up your webhooks in Sinch Mailgun.

You might be asking yourself why you can’t just send it directly to the Discord webhook URL.

There are two reasons:

  • You cannot change or control the payload that Sinch Mailgun sends to a webhook.
  • The receiving webhook on Discord also expects the payload to be in a specific format.

This is why you need an intermediary script, like your Python script, to pull apart the data from Sinch Mailgun and convert it into a format that Discord can understand.

You can start by creating a webhook for delivered emails. Navigate to the Webhooks section under the Sending menu:

And click the Add webhook button:

Select the Event type as Delivered Messages and enter the URL for your Python application with the correct endpoint for handling delivered messages:

Finally, click the Create Webhook button. Your newly created webhook should now appear in the list:

You can repeat this procedure by adding webhooks for the other event types (like bounced) and pointing them to the corresponding endpoint in your application.

Once you’ve created the necessary webhooks, you need your webhook signing key. On the same page that shows the list of your created webhooks, your signing key should also be visible:

Copy this key, and update your Python variable called <REPLACE_WITH_WEBHOOK_SIGNING_KEY> with the key you just copied.

Test it all

Now that every part of the chain is set up and waiting, you can send a test email to the mailbox you control.

You can use a simple curl command to send an email via the Sinch Mailgun API. You just need to create an API key, which you can do by following the steps listed in this article. Remember to copy your API key the moment you create it since it is displayed only once for security purposes. Otherwise, you need to delete and recreate the key.

Once you have your key, you can use curl to send a test email, like this:

If the API call is successful, you should receive a JSON payload that lets you know that the call went through:

If everything goes well, you should receive a message in your Discord channel:

The moment the email is delivered successfully, the alert is received on Discord. You have now successfully integrated a Python webhook that Sinch Mailgun can send data to. In turn, the Python webhook extracts and formats the necessary data from the POST data from Sinch Mailgun and sends a neatly formatted message to your Discord server.

Taking the next steps

There is some work left to do, but all the basic building blocks are now in place. You can modify the Python script as you see fit.

Here are some things to consider:

This basic setup can be extended to cater to different teams across your company:

  • Engineering teams can set up alerts for events like permanent delivery failures or delayed deliveries, so they can react quickly to system issues or mail server misconfigurations.
  • Support teams can monitor events, such as dropped or bounced, for specific critical emails, like a password reset or an invoice.
  • Marketing teams may want to track engagement-related events, like unsubscribed, opened, or complained. With slight modifications to the script, you can post alerts only when specific conditions are met; for example, there’s a high unsubscribe rate on a new campaign.

Wrapping up

In this tutorial, you learned how to call webhooks for specific event types so that [Sinch Mailgun[(https://www.mailgun.com/) can send alerts directly to Discord via a Python webhook. Sinch Mailgun helps you create workflows like this so you can ensure critical alerts are delivered instantly to the right communication channels. This reduces manual intervention, improves response times, and streamlines your engineers’ workflows.

This is just a small sample of the type of automation that you can achieve using Sinch Mailgun. Sign up for a free account, explore their documentation, and discover more ways that Sinch Mailgun can help you optimize your email workflows and integrations.

Keep me posted! Get great resources in your inbox every week.

What this article says