Recipes
=======
This section demonstrates how to chain multiple Actions together to build intelligent and automated email workflows.
The following examples assume that you have already created your MailTrigger mailbox, Routes, Rules, and any required Custom Data.
1. Webhook (API) Action → JS Action → Telegram Action
------------------------------------------------------
Use Case
~~~~~~~~
Upon receiving an email, call an internal company API to get a project-owner mapping. Then determine which owner to notify based on the email content, and finally send a Telegram message to the appropriate recipient.
Overall Flow
~~~~~~~~~~~~
1. API Action
^^^^^^^^^^^^^
- **Purpose**: Call your internal HTTP API (Webhook) to retrieve a mapping between project names and owner emails.
- **Parameters**:
- ``method``: ``"GET"``
- ``webhook_url``: e.g., ``https://api.internal.local/getProjectOwners``
- ``headers``: ``{"Authorization": "Bearer $API_TOKEN"}``
- **Attach Result**: Enable *Attach Result to Mail* to save the API response JSON as an attachment.
2. JS Action
^^^^^^^^^^^^
- **Purpose**: Parse the API result from the attachment and dynamically modify the recipients based on the project mentioned in the email.
- **Parameters**:
- ``jsCode``:
.. code-block:: javascript
// mail: provided variable containing all email fields
// $ATTACHMENT_LAST1 is the API JSON string result
const resp = JSON.parse(mail.attachments[mail.attachments.length - 1]);
const bodyText = mail.body;
let ownerEmail = null;
// Example: { "projectA": "alice@example.com", "projectB": "bob@example.com" }
Object.entries(resp).forEach(([project, email]) => {
if (bodyText.includes(project)) {
ownerEmail = email;
}
});
if (!ownerEmail) {
return { attach: false, receivers: mail.receivers };
}
return { attach: false, receivers: [ownerEmail] };
- **Attach Result**: Disabled. This JS action directly modifies ``mail.receivers``.
3. Telegram Action
^^^^^^^^^^^^^^^^^^
- **Purpose**: Push the processed email content to the responsible party via Telegram.
- **Parameters**:
- ``botToken``: ``$telegramBotToken`` (from Custom Data)
- ``chatId``: ``$telegramChatId`` (from Custom Data)
- ``title``: ``$SUBJECT``
- ``body``: ``$BODY``
.. note::
- You must define ``telegramBotToken`` and ``telegramChatId`` in the mailbox's Custom Data, using the recipient's email as the key.
- Route "Execution Mechanism" should be set to **Sequential** to ensure the three Actions are executed in order.
.. note::
Real-world Example
This use case reflects a real internal use case at MailTrigger for routing server alerts to the right person. If you're interested in how this is applied in production,
.. raw:: html
Read the story
2. LLM Action + Auto Respond
----------------------------
Use Case
~~~~~~~~
Automated customer support: When an incoming customer email is received, use an LLM to draft a reply and then send the finalized reply using AutoRespond.
Overall Flow
~~~~~~~~~~~~
1. LLM Action
^^^^^^^^^^^^^
- **Purpose**: Send the customer's email content to an LLM and generate a reply draft.
- **Parameters**:
- ``prompt``:
.. code-block:: text
Please write a professional and friendly reply to the following customer email,
including a polite closing
- ``max_retry``: ``3``
- ``temperature``: ``0.7``
- **Attach Result**: Enable *Attach Result to Mail* so the LLM's reply is saved as an attachment.
2. AutoRespond Action
^^^^^^^^^^^^^^^^^^^^^
- **Purpose**: Extract the LLM's reply from the attachment and send it as the formal response.
- **Parameters**:
- ``subject``: ``Re: $SUBJECT``
- ``body``: ``$ATTACHMENT_LAST1``
- ``smtp_server``: *your real SMTP host*
- ``smtp_port``: ``587``
- ``smtp_tls``: ``true``
- ``smtp_username``: *your sending email address*
- ``smtp_password``: *password for the sending address*
.. note::
- Set the Route Execution Mechanism to **Sequential**.
- Ensure your User Settings page is configured with a valid LLM provider, API key, and model.
- If you want to prevent other Routes from triggering afterward, set "Pass To Next" to **False** in the Route settings.
.. note::
Real-world Example
This use case is inspired by a real MailTrigger customer support setup, where LLMs help draft and automate replies. For more details,
.. raw:: html
Read the story