---
title: Mailhook-triggered AI agent
slug: mailhook-triggered-ai-agent
image: https://archbee-image-uploads.s3.amazonaws.com/oAyFj2GHlBeBVWF5OAir2/0hwqpiYZYkB8ltittUnBp_triggers-1.png
docTags: 
createdAt: 2026-03-19T11:05:57.391Z
---

This mailhook-triggered AI agent scenario watches for new emails, and the agent replies to them. Mailhooks (email webhooks) immediately trigger scenarios in response to new emails, rather than [on a schedule](docId\:SclqhRvEy8NQgRTM5AMnP). &#x20;

![](https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/qGNDOupP6qFeiew9ABCTg_mailhook-triggered-ai-agent.png)

## Prerequisites

- Two email accounts, such as a business email address and a personal email address

**This example uses Gmail.** If you have a different email provider, see its documentation for equivalent settings in the relevant steps.&#x20;

## Step 1. Add a Custom mailhook module

The **Webhooks&#x20;**> **Custom mailhook&#x20;**&#x6D;odule generates an email address (mailhook) that your email provider forwards new emails to, triggering the scenario.

To add a **Custom mailhook&#x20;**&#x6D;odule:

::::WorkflowBlock
:::WorkflowBlockItem
In the Scenario Builder, in the top-left corner, name your scenario and click **Save**.&#x20;
:::

:::WorkflowBlockItem
Click the giant plus.&#x20;
:::

:::WorkflowBlockItem
In the app search, search for and click **Webhooks**.&#x20;
:::

:::WorkflowBlockItem
Select the **Custom mailhook** module.&#x20;
:::

:::WorkflowBlockItem
In the module settings, in **Mailhook**, click **Add**. &#x20;
:::

:::WorkflowBlockItem
In **Webhook name**, name the mailhook. For example, use the scenario name.&#x20;
:::

:::WorkflowBlockItem
Click **Save**. You'll now see the generated mailhook to use in later steps.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/_8Wzdo8HuFT2alJxIZ-mV-20260310-151201.png" size="70" width="558" height="419" position="center" darkWidth="558" darkHeight="419" showCaption="false"}
:::

:::WorkflowBlockItem
Copy the address to your clipboard and click **Save**. You'll later update your email settings to forward emails to it.&#x20;
:::

:::WorkflowBlockItem
Click **Save&#x20;**&#x69;n the Scenario toolbar.&#x20;
:::
::::

You've now added a **Webhooks&#x20;**> **Custom mailhook&#x20;**&#x6D;odule.&#x20;

## Step 2. Add your mailhook as a forwarding email&#x20;

In the email account where new emails trigger the scenario, add the mailhook as a forwarding address so your email provider sends new emails to it.&#x20;

To add the mailhook as a forwarding address:&#x20;

::::WorkflowBlock
:::WorkflowBlockItem
Open your  Gmail account.&#x20;
:::

:::WorkflowBlockItem
Click the **Settings&#x20;**&#x69;con in the top-right menu, and click **See all settings**.&#x20;
:::

:::WorkflowBlockItem
Go to the **Forwarding and POP/IMAP** tab.&#x20;
:::

:::WorkflowBlockItem
Click **Add a forwarding address**.&#x20;
:::

:::WorkflowBlockItem
Paste the mailhook that you copied earlier.&#x20;
:::

:::WorkflowBlockItem
Agree to proceed in all remaining steps.
:::
::::

You've now added the mailhook as a forwarding address in Gmail.&#x20;

## Step 3. Create an email filter&#x20;

To send only specific incoming emails to the mailhook, rather than all emails, create a filter in Gmail.&#x20;

To create an email filter:&#x20;

:::::WorkflowBlock
:::WorkflowBlockItem
In **Settings&#x20;**&#x69;n your Gmail account, go to the **Filters and Blocked Addresses** tab.&#x20;
:::

:::WorkflowBlockItem
Click **Create a new filter**.
:::

::::WorkflowBlockItem
In **From**, enter the email address associated with the email account that you're in now. &#x20;

:::hint{type="info"}
Use your own email address so you can send yourself an email and reply to it. Your email reply passes an important header into Make called `references` that you must map later in the scenario.
:::
::::

:::WorkflowBlockItem
Click **Create filter**.&#x20;
:::

:::WorkflowBlockItem
Select **Forward it to:&#x20;**&#x61;nd select the mailhook that you added in the previous step.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/vi30Xf7yw6_bx_nXKy5BV-20260311-150732.png" size="70" width="806" height="639" position="center" darkWidth="806" darkHeight="639" showCaption="false"}
:::

:::WorkflowBlockItem
Click **Create filter**.&#x20;
:::
:::::

You've now created an email filter, so only specific emails go to the mailhook.&#x20;

## Step 4. Send a test email to the Custom mailhook module

To test that your **Custom mailhook** module receives forwarded emails from Gmail:

::::WorkflowBlock
:::WorkflowBlockItem
In the Scenario Builder, click **Run once** on the Scenario toolbar.&#x20;
:::

:::WorkflowBlockItem
In Gmail, send yourself an email.&#x20;
:::

:::WorkflowBlockItem
Once the mailhook receives the email, you can click the output bubble of the **Custom mailhook&#x20;**&#x6D;odule to view the email properties, such as headers.&#x20;
:::
::::

You've now sent a test email to yourself. Next, reply to it.&#x20;

## Step 5. Reply to the test email&#x20;

Reply to the first test email to pass headers that are only available in email replies —`in-reply-to` and `references`—into the scenario for mapping. You'll need these values for replying to emails.&#x20;

To reply to the test email:&#x20;

::::WorkflowBlock
:::WorkflowBlockItem
Click **Run once** on the Scenario toolbar.&#x20;
:::

:::WorkflowBlockItem
Go to your Gmail account.&#x20;
:::

:::WorkflowBlockItem
Reply to the email that you sent yourself.&#x20;
:::

:::WorkflowBlockItem
Once the mailhook receives the email, click the output bubble to expand `Headers` and view the values you'll use in later steps:&#x20;

- `message-ID`: The unique ID of an email
- `in-reply-to`: The message ID of the email being replied to&#x20;
- `references`: A list of message IDs in a single thread of emails, with the first ID being the initial email
:::
::::

The **Webhooks&#x20;**> **Custom mailhook** is complete now that it has reply email output data.

## Step 6. Add a Run an agent module

To add the **Make AI Agent (New)** > **Run an agent&#x20;**&#x6D;odule:

:::::WorkflowBlock
:::WorkflowBlockItem
Click the plus icon next to the **Webhooks&#x20;**> **Custom mailhook&#x20;**&#x6D;odule.&#x20;
:::

:::WorkflowBlockItem
In the app search, search and click **Make AI Agent (New)**.&#x20;
:::

:::WorkflowBlockItem
Click the **Run an agent** module.&#x20;
:::

::::WorkflowBlockItem
In **Connection**, select an existing AI provider connection from the dropdown or click **Add&#x20;**&#x74;o add a new one.&#x20;

:::hint{type="info"}
If you don't want to create an account with an AI provider, select **Make's AI Provider**.&#x20;
:::
::::

:::WorkflowBlockItem
In **Model**, select a model from your chosen AI provider.
:::

:::WorkflowBlockItem
In **Instructions**, describe who the agent is and what it does. Alternatively, copy-paste the following: You are a helpful agent who replies to emails.&#x20;
:::

::::WorkflowBlockItem
In **Input**, tell the agent to read the email content and answer in HTML. You can copy-paste the following:&#x20;

Read the content of this email \</content> Text \</content>, and answer in HTML format. Directly reply to the email. Don't add any internal instructions or provide an email signature.&#x20;

:::hint{type="info"}
While optional, XML tags (\</content>) clearly separate data (`Text`) from the rest of the instructions.&#x20;
:::
::::

:::WorkflowBlockItem
Replace Text with the `Text` value from the **Webhooks** > **Custom mailhook** module.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/LqdAYMZaecRD0SbybR8XS-20260312-124822.png" size="60" width="343" height="191" position="flex-start" darkWidth="343" darkHeight="191" showCaption="false"}
:::

::::WorkflowBlockItem
In **Conversation ID**, enter the following function: `ifempty(` `first(` `split(` Headers: references`;` `space` `)` `)` `;` Headers: message-id`)`

:::hint{type="info"}
This function uses the first message ID listed in the `reference` header, and if empty, uses the `message ID`. The` split(`splits the reference array into individual values and the `first(` uses the first value.&#x20;
:::
::::

:::WorkflowBlockItem
Replace the text in the function (Headers: reference and Headers: message-id) with the corresponding values from the **Webhooks&#x20;**> **Custom mailhook** module.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/7EdO6nIaT2bTJgWMtlnA2-20260312-132350.png" size="70" width="527" height="236" position="center" darkWidth="527" darkHeight="236" showCaption="false"}
:::

:::WorkflowBlockItem
Click **Save&#x20;**&#x69;n the Scenario toolbar.&#x20;
:::
:::::

You've now added a **Run an agent&#x20;**&#x6D;odule.

## Step 7. Add a Send an email module

The **Gmail&#x20;**> **Send an email&#x20;**&#x6D;odule replies to emails with agent-generated answers from the **Make AI Agent (New)** >**&#x20;Run an agent&#x20;**&#x6D;odule.&#x20;

To add a **Send an email&#x20;**&#x6D;odule:

::::WorkflowBlock
:::WorkflowBlockItem
Click the plus icon next to the **Make AI Agent (New)&#x20;**> **Run an agent** module.&#x20;
:::

:::WorkflowBlockItem
In the app search, search for **Gmail&#x20;**&#x61;nd clic&#x6B;**&#x20;Send an email**.&#x20;
:::

:::WorkflowBlockItem
In the module settings, in **Connection**, select the Gmail connection that you used to create the mailhook.
:::

:::WorkflowBlockItem
In **To**, map the `Sender: Email address` value from the **Webhooks&#x20;**>**&#x20;Custom mailhook** module.&#x20;
:::

:::WorkflowBlockItem
In **Subject**, map the `Subject` value from the **Webhooks&#x20;**> **Custom mailhook&#x20;**&#x6D;odule.&#x20;
:::

:::WorkflowBlockItem
In **Body type**, select `Raw HTML` because you requested HTML in the agent instructions.&#x20;
:::

:::WorkflowBlockItem
In **Content**, map the `Response`value from the **Make AI Agent (New)** > **Run an agent** module.&#x20;
:::

:::WorkflowBlockItem
Toggle **Advanced settings**.&#x20;
:::

:::WorkflowBlockItem
In **Additional email headers**, add these email headers:

- **Email header 1**:&#x20;
  - In **Key**, enter in-reply-to.
  - In **Value**, map the `Headers: message-id` value from the **Webhooks** > **Custom mailhook** module.&#x20;
- **Email header 2**:&#x20;
  - In **Key**, enter references.&#x20;
  - In **Value**, map the `Headers: references` and `Headers: message-id` values from the **Webhooks&#x20;**> **Custom mailhook** module.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/dS3uBwLPQ-aP1j1m_oVYQ-20260312-154447.png" size="60" width="534" height="638" position="center" darkWidth="534" darkHeight="638" showCaption="false"}
:::

:::WorkflowBlockItem
Click **Save**.&#x20;
:::

:::WorkflowBlockItem
Click **Save&#x20;**&#x6F;n the Scenario toolbar.&#x20;
:::
::::

Your email webhook-triggered AI agent scenario is now ready to test again.&#x20;

## Step 8. Update the email filter and test it

Based on your current email settings, Gmail forwards emails from yourself—including agent replies to them—to the mailhook.&#x20;

To prevent an infinite loop, where each agent reply triggers the scenario, add a different email address to your email filter, such as your personal email address, and test it from that account.

To update the email filter and test it:&#x20;

::::WorkflowBlock
:::WorkflowBlockItem
In Gmail, click the **Settings&#x20;**&#x69;con, and click **See all settings**.&#x20;
:::

:::WorkflowBlockItem
Click **Filters and Blocked Addresses**.&#x20;
:::

:::WorkflowBlockItem
Find your existing email filter and click **edit**.&#x20;
:::

:::WorkflowBlockItem
In **From**, add a different email address. &#x20;
:::

:::WorkflowBlockItem
Click **Continue**, then click **Update filter**.&#x20;
:::

:::WorkflowBlockItem
In the email account associated with the new address, send an email to the original email address.
:::

:::WorkflowBlockItem
In the Scenario Builder, click **Run once&#x20;**&#x6F;n the Scenario toolbar to test if agent replies work.&#x20;
:::

:::WorkflowBlockItem
Return to the account associated with the new email address. You now have an email thread with the initial email (**1**) and the agent reply (**2**).&#x20;

![](https://api.archbee.com/api/optimize/oAyFj2GHlBeBVWF5OAir2/ylyWdD7SlpHm8HeC0VD9w-20260313-094129.png)
:::
::::

You've now created a mailhook-triggered AI agent scenario, where your target email account forwards emails to a mailhook, and the agent immediately replies to them.&#x20;

Next, you can tailor the email filter with additional specifics, depending on your use case.&#x20;
