> ## Documentation Index
> Fetch the complete documentation index at: https://docs.twenty.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 受信メールへの自動返信

> AI を使用して受信メールをトリアージし、スレッド返信を自動的に送信するワークフローを構築します。

受信メールに数秒で対応 — 数時間ではなく。 このワークフローは AI エージェントを使用してノイズ（ニュースレター、スパム、自動返信）を除外し、実際のメッセージに対するパーソナライズされた返信を下書きし、元の会話内でスレッド返信として送信します。

## メールスレッドの仕組み

すべてのメールには、送信者のメールサーバーによって割り当てられる一意の識別子である非表示の `Message-ID` ヘッダーが含まれています。 When you reply to an email, your mail client sets an `In-Reply-To` header referencing that fingerprint. That's how Gmail, Outlook, and every other client groups messages into threads.

In Twenty, that fingerprint is stored as `headerMessageId` on the Message object. Your workflow grabs it and passes it into the Send Email action's In-Reply-To field.

## Building the workflow

### Step 1: Create a new workflow

Head to **Settings -> Workflows** and click **+ New Workflow**.

### Step 2: Trigger on incoming messages

Pick **When a Record is Created** and choose **Messages**.

Every time an email lands in Twenty, this fires.

<img src="https://mintcdn.com/twenty/M0obaMHx4sAZxfpw/images/user-guide/workflows/auto-reply/workflow-overview.png?fit=max&auto=format&n=M0obaMHx4sAZxfpw&q=85&s=c9f94783097adfd9e8116bafcabe0435" style={{width:'100%'}} width="2992" height="1708" data-path="images/user-guide/workflows/auto-reply/workflow-overview.png" />

### Step 3: Look up who sent it

Add a **Search Records** action.

The sender's address isn't on the message itself — it's on the related Message Participant record.

| フィールド      | 値                               |
| ---------- | ------------------------------- |
| **オブジェクト** | Message Participants            |
| **フィルター**  | Message **is** `{{trigger.id}}` |
| **フィルター**  | Role **is** From                |
| **制限**     | 1                               |

This gives you the sender's email in `handle` and their name in `displayName`.

<img src="https://mintcdn.com/twenty/M0obaMHx4sAZxfpw/images/user-guide/workflows/auto-reply/find-sender.png?fit=max&auto=format&n=M0obaMHx4sAZxfpw&q=85&s=4ff16df7dfdd89f59f8c4861b63e5313" style={{width:'100%'}} width="2992" height="1708" data-path="images/user-guide/workflows/auto-reply/find-sender.png" />

### Step 4: AI triage and draft reply

Add an **AI Agent** action. This single step does two things: decides whether the email deserves a reply, and if so, writes one.

Use a prompt like:

```
You are an email triage assistant for a sales team. Read the following
inbound email and decide if it deserves a reply.

Subject: {{trigger.subject}}
Body: {{trigger.text}}
From: {{Find Sender.first.displayName}} ({{Find Sender.first.handle}})

If this email is spam, a newsletter, an automated notification, or
otherwise does not need a human reply, respond with exactly: SKIP

Otherwise, write a short, professional reply (3-4 sentences max) that:
- Acknowledges their specific message
- Lets them know someone from the team will follow up shortly
- Is warm but not overly casual

Respond with only the reply text, no subject line or greeting prefix.
```

The AI Agent outputs its response in a `response` field that the next steps can reference.

<img src="https://mintcdn.com/twenty/M0obaMHx4sAZxfpw/images/user-guide/workflows/auto-reply/ai-triage.png?fit=max&auto=format&n=M0obaMHx4sAZxfpw&q=85&s=5a52cb6437ba39ffbb081a564c8e3d38" style={{width:'100%'}} width="2992" height="1696" data-path="images/user-guide/workflows/auto-reply/ai-triage.png" />

### Step 5: Branch on the AI decision

Add an **If/Else** action to check whether the AI decided to reply or skip.

| フィールド       | 値                                               |
| ----------- | ----------------------------------------------- |
| **条件**      | AI Agent `response` **does not contain** `SKIP` |
| **If true** | Continue to Send Email                          |
| **Else**    | Do nothing (workflow ends)                      |

Spam, newsletters, and auto-generated messages get dropped. Everything else moves to the next step.

<img src="https://mintcdn.com/twenty/M0obaMHx4sAZxfpw/images/user-guide/workflows/auto-reply/should-reply.png?fit=max&auto=format&n=M0obaMHx4sAZxfpw&q=85&s=d551a03a76c47b8a9a83540514667285" style={{width:'100%'}} width="2992" height="1696" data-path="images/user-guide/workflows/auto-reply/should-reply.png" />

### Step 6: Send a threaded reply

Add a **Send Email** action on the "if true" branch. Click **Advanced options**, then **Add In-Reply-To**.

| フィールド           | 値                                      |
| --------------- | -------------------------------------- |
| **宛先**          | `{{Find Sender.first.handle}}`         |
| **件名**          | `Re: {{trigger.subject}}`              |
| **本文**          | `{{AI Triage & Draft Reply.response}}` |
| **In-Reply-To** | `{{trigger.headerMessageId}}`          |

The In-Reply-To field is what makes this a reply instead of a new conversation. The recipient sees it threaded under the original email in Gmail, Outlook, or any other client.

<img src="https://mintcdn.com/twenty/M0obaMHx4sAZxfpw/images/user-guide/workflows/auto-reply/send-email.png?fit=max&auto=format&n=M0obaMHx4sAZxfpw&q=85&s=8ada38d0a5112b949837eb8e3852bfea" style={{width:'100%'}} width="2992" height="1696" data-path="images/user-guide/workflows/auto-reply/send-email.png" />

<Tip>
  **In-Reply-To** expects a `message.headerMessageId` from the trigger — it's the email's unique fingerprint, not a recipient address. If you leave it empty, the email still sends, just as a standalone message.
</Tip>

<Warning>
  Gmail uses the subject line to group messages into threads. The subject **must** start with `Re:` (including the colon and space) for Gmail to display the reply inside the original thread. Without it, the reply will appear as a separate conversation — even if the In-Reply-To header is set correctly.
</Warning>

### Step 7: Test and activate

Hit **Test**, then check your email client. The reply should appear nested under the original message.

Activate when you're happy with it.

## Ideas to build on

* **Only reply to VIPs** — add a branch that checks the sender's domain or whether they exist as a Contact in Twenty
* **Route by intent** — use separate AI Agent prompts to handle sales inquiries differently from support requests
* **Enrich before replying** — add a Search Records step to pull the sender's company or deal history into the AI prompt for more personalized replies
