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/getProjectOwnersheaders:{"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:// 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:$SUBJECTbody:$BODY
Note
You must define
telegramBotTokenandtelegramChatIdin 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,
Read the story2. 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:Please write a professional and friendly reply to the following customer email, including a polite closing
max_retry:3temperature: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: $SUBJECTbody:$ATTACHMENT_LAST1smtp_server: your real SMTP hostsmtp_port:587smtp_tls:truesmtp_username: your sending email addresssmtp_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,
Read the story3. LLM Action + SMTP Action — Dynamic Prompt via API parameters#
Use Case#
Bob wants to send emails whose content is generated on the fly by an LLM.
He sets his mailbox route to run LLM → SMTP.
In the LLM Action, the Prompt parameter is set to %BODY_PROMPT% so that he can pass the actual prompt dynamically via the send-mail API.
Overall Flow#
1. LLM Action#
Purpose: Generate dynamic content using a prompt provided at runtime.
Parameters:
prompt:%BODY_PROMPT%This tells the action to read the prompt from the API’sparameters.BODY_PROMPT.Output: Configure the LLM Action to emit its result as an attachment (e.g., a text attachment).
Attach Result: Enabled. The LLM’s output is saved as an attachment.
2. SMTP Action#
Purpose: Send the email using the LLM-generated content as the body.
Parameters: -
subject:$SUBJECT(use the original mail subject) -body:$ATTACHMENT_LAST1(Use the LLM attachment’s text as the email body.)Attach Result: Disabled. The SMTP action sends the final email.
Note
The SMTP Action reads the LLM-produced attachment and replaces the outgoing email body with that content.
Don’t know what $ATTACHMENT_LAST1 means? Check out how to attach the LLM response.
Endpoint#
POST /api/v1/mailbox/{id}/mail/send
Authentication#
Include your MailTrigger API token in the header:
Authorization: Token <YOUR_API_TOKEN>.
Request JSON#
to(string)Recipient email address.
parameters(object)Must include the runtime prompt in the format
{"BODY_PROMPT": "<your prompt here>"}. The keys and values can be customized.subject(string) (optional)The original email subject line. (You can leave this blank and still set up the mail subject in the action parameters.)
body(string) (optional)The original email body. (You can leave this blank and still set up the mail body in the action parameters.)
Example: cURL (send with a dynamic LLM prompt)#
curl -X POST \
https://app.mailtrigger.app/api/v1/mailbox/123/mail/send \
-H "Content-Type: application/json" \
-H "Authorization: Token YOUR_API_TOKEN" \
-d '{
"to": "customer@example.com",
"subject": "MailTrigger Product Information",
"parameters": { "BODY_PROMPT": "Write a concise product introduction for MAILTRIGGER." }
}'
What Happens#
The LLM Action runs first, taking the prompt from
parameters.BODY_PROMPT.The LLM’s result is emitted as an attachment.
The SMTP Action then reads that attachment and uses its text as the final email body, sending the message from the configured MAILBOX.
To change what gets emailed, simply change
parameters.BODY_PROMPTin your API call — no template edits needed.