---
id: guides-send-mailgun-events-to-tinybird
title: Send Mailgun Events to Tinybird
meta:
    description: Learn how to send Mailgun events to Tinybird using webhooks and the Events API.
---

# Send Mailgun events to Tinybird

[Mailgun](https://www.mailgun.com) is a platform for sending email, and it provides a way to send events to Tinybird using webhooks.

Read on to learn how to send events from Mailgun to Tinybird.

## Before you start

Before you connect Mailgun to Tinybird, ensure:

* You have a Mailgun account.
* You have a Tinybird workspace.

## Connect Mailgun to Tinybird

Mailgun provides a variety of [webhook event types](https://mailgun-docs.redoc.ly/docs/mailgun/user-manual/events/#event-structure) that you can use to send events to Tinybird.

This guide covers the base case for sending Mailgun events to Tinybird.

1. In Mailgun, go to **Send** > **Sending** > **Webhooks**.
   
2. Select **Domain** and **Add webhook**.

3. In your Tinybird project, create a data source called `mailgun`. You can follow this [schema](https://github.com/tinybirdco/tinynest/blob/main/tinybird/datasources/mailgun.datasource):

```tb {% title = 'Data Source schema for Mailgun events %}
SCHEMA >
  `event_time` DateTime `json:$.tinybirdIngestTime` DEFAULT now(),
  `event_type` String `json:$.event-data.event` DEFAULT 'unknown',
  `event` JSON `json:$` DEFAULT '{}'

ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(event_time)"
ENGINE_SORTING_KEY "event_time"
```

Using the [JSON Data Type](/sql-reference/data-types/json) you can store the semi-structured data you receive from Mailgun in a single column. You can later retrieve various events and their metadata as needed in your pipes.

{% callout type="caution" %}
The `JSON` data type is in private beta. If you are interested in using this type, contact Tinybird at <support@tinybird.co> or in the [Community Slack](/community).
{% /callout %}

4. From Tinybird Cloud, copy a token with privileges to append to the data source you created. You can use the admin token or create one with the required scope.

5. Back in Mailgun, paste the Events API URL in your Webhook Endpoint URL. Use the query parameter `name` to match the name of the data source you created in Tinybird.

```
{% user("apiHost") %}/v0/events?name=mailgun&format=json&token={% user("userToken") %}
```

Make sure to use the `format=json` query parameter.

{% snippet title="api-region-reminder" /%}

7. Select **Event type** and choose the event you want to send to Tinybird. You can use the same Tinybird data source for multiple events.

8. Select **Create webhook** abd you're done. 

Check the status of the integration from the **Log** tab in the Tinybird `mailgun` data source. 
    
## See also

* [Mailgun Events](https://mailgun-docs.redoc.ly/docs/mailgun/user-manual/events/#event-structure)