# Mailgun

### Connection <a href="#connect" id="connect"></a>

When you're setting up your first workflow with Mailgun, you'll need to add your API key so that Mailgun is a connected app within MESA.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FeHkLlBf1iSS10b7N5K1e%2Fimage.png?alt=media&#x26;token=f04b351f-7265-461b-b216-e2542922d76b" alt=""><figcaption></figcaption></figure>

From your Mailgun account dashboard, click on your profile from the top right hand corner and then click on [API Security.](https://app.mailgun.com/settings/api_security)

Next, click on the eye icon next to Private API key. Copy and paste it in the API Key field.

Once the API Key is entered, click on Add Connection to connect MESA with Mailgun. Lastly, click on the Done button and hit the **Save** button at the top of or below the workflow to save your changes.

### Configure <a href="#configuring" id="configuring"></a>

#### Select your Domain <a href="#domain" id="domain"></a>

All Mailgun [Triggers](https://docs.getmesa.com/workflow-builder/triggers) require you to select a Mailgun Domain that MESA should work with. Click on the Domain drop-down menu and select your domain.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FjQs8bBbEcSNYSBLneLJN%2FEF-mailgun-domain.png%20-%20Step%202.png?alt=media&#x26;token=fc4238fa-cabe-4430-86ae-953686ffc6c4" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**🗒️ Note**: After saving the workflow for the first time, the domain selected in the Trigger cannot be changed. If you need to change the domain, please create a new workflow.
{% endhint %}

Once selected and after ensuring that you have selected the correct domain, hit the Save button at the top of or below the workflow to save your changes.

#### Send Message Action <a href="#send-message" id="send-message"></a>

When adding a Mailgun Send Message action, you will need to fill out some required fields before being able to save your workflow.

**Required Fields:**

* **Domain (required):** Select a domain that MESA should work with. Review [this section](#domain) if you are unsure on what to select
* **From (required):** Input an email address for the email's From setting
* **To (required):** Email address of the recipient(s). You can use commas to separate multiple recipients and can utilize [MESA's Variables feature](https://docs.getmesa.com/workflow-builder/fields/variables) to automatically input the customer's email address
* **Subject (required):** Email's Subject line
* **Message (required):** Email's body message. This cannot be used with the Template Variables fields.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2F5AdU02FmVuEA0qP0feU4%2FEF-mailgun-send-message-required-fields.png%20-%20Step%202.png?alt=media&#x26;token=65437d6f-72a1-4c1c-88b3-b3180c342b52" alt=""><figcaption></figcaption></figure>

**More Options** variable&#x73;**:**

* **Template:** You can select any of your existing Mailgun templates to automatically format the emails sent by MESA. To locate your Templates: Mailgun dashboard > Sending (from left hand sidebar) > Templates
* **Template Variables:** Variables used in an email template. This cannot be used with the Text field. Continue reading to the next section for more information.

**Attachments**

You can attach attachments into your email by inputting the URL of the attachment.

Click More Options, scroll down and select the URL attachments variable.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FTn8hgKmJqwz5XMal9o0c%2FEF-mailgun-attachments.png%20-%20Step%202.png?alt=media&#x26;token=5c1f6856-c28d-4472-ab91-d81bee5276be" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FdNz3n7qJV3zXmCo4HBLl%2FEF-mailgun-attachments.png%20-%20Step%203.png?alt=media&#x26;token=d59b3afa-8d96-4a09-a8cb-1c951ff08982" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2F3fP97BhDHDUWbSWAPjlm%2FEF-mailgun-attachments.png%20-%20Step%204.png?alt=media&#x26;token=8a406a0d-7037-4191-977e-74390d81c923" alt=""><figcaption></figcaption></figure>

We use the file's type extension to determine the mime type of the file. For instance, if a file ends with .pdf, we will assume the mime type is application/pdf because of the extension. Similarly, if the file ends with .png, we will assume its mime type is image/png. Therefore, it is highly recommended that the attachment URLs end with the file extension.

**Adding Template Variables into the Send Message Action**

If your Mailgun template utilizes Variables, you can automatically input data into these variables which are included in the Email's Body.

1\. To set this up, [login into your Mailgun account](https://app.mailgun.com/app/dashboard). Then, click on Sending under Email and then click on Templates.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2Fghh7LCMDpBBQkPrMiQPq%2FEF-mailgun-template-variables_png_-_Step_2.png?alt=media&#x26;token=be17445d-bae6-4a33-a964-df4d455e0112" alt=""><figcaption></figcaption></figure>

2\. Locate the template that you want MESA to use in the Send Message action and then click on it.

3\. When viewing the template, find your Variables which would look something like this: {{customer\_name}}

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2F1e90AiMXietbuiLC6St4%2FEF-mailgun-variable.png%20-%20Step%202.png?alt=media&#x26;token=f9a27106-7695-49cf-aa01-523b5928d3c7" alt=""><figcaption></figcaption></figure>

4\. Back into your MESA workflow's Send Message action in Configure, scroll down and select More Options, locate the Template Variables section, and click on Add Field.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FHS519hOTDTLGUKawryHF%2FEF-mailgun-template-variable-custom-field.ng%20-%20Step%202.png?alt=media&#x26;token=683e6ec7-5794-40bb-803d-ede0666a90ae" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2Fec3X1jKZCWkCzEiK4s4b%2FEF-mailgun-template-variable-custom-field.ng%20-%20Step%203.png?alt=media&#x26;token=b0db61c0-f8b4-4fa6-b4aa-b248ffa1f159" alt=""><figcaption></figcaption></figure>

5\. A Field name field will then display. Input the name of the Variable. Example: customer\_name. Click Save.

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FwQWIPKKuuA1FhR6MOjgB%2FEF-mailgun-template-variable-custom-field.ng%20-%20Step%204.png?alt=media&#x26;token=4edfcb6e-7c92-4e1d-9ac9-cd7073d6473d" alt=""><figcaption></figcaption></figure>

6\. For the empty field below, you will want to input that variable from your Mailgun template. Example: {{customer\_name}}

<figure><img src="https://3425906282-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1H6u1HQc3Iew7ATmmiCi%2Fuploads%2FL5BnUmLs8gb88shvNYlq%2FEF-mailgun-template-variable-custom-field.ng%20-%20Step%205.png?alt=media&#x26;token=bdd5d118-30e3-4f92-91d4-474a95952718" alt=""><figcaption></figcaption></figure>

7\. To add more Variables if needed, please repeat steps 4-6.

8\. Once you are done, you can save your changes! When an automation runs, your email will automatically contain important information.

### Technical Notes <a href="#limitations" id="limitations"></a>

* Please note that the email message, including attachments, cannot exceed the per-message size limit of 25MB or it may be permanently lost.
* We do not support sharing URLS from Google Drive or Dropbox at this time or the ability to upload a file directly in MESA. For example, the attachment URL should be publicly available and MESA should be able to directly access the file without downloading it. We recommend uploading the files to a third party service like [Shopify Files](https://help.shopify.com/en/manual/shopify-admin/productivity-tools/file-uploads) and then copying the URL from there.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.getmesa.com/connect/mailgun.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
