# Every reply on the right thread

A reply from a new sender, under a new subject or days later lands on the conversation it answers. It reaches your webhook with the thread\_id of that conversation.

[Get started](/signup)
[Documentation](https://docs.aiinbx.com/guides/threads)

Four mails that look unrelated: the RFQ you sent, Dana's out-of-office auto-reply, a reply from Marco (a new sender with a new subject), and Dana's confirmation four days later. They fold into one conversation, thread thr\_8f2c, in order, with the last two smart-matched.

Threads

## One conversation, however the replies arrive

Every send opens a thread or joins one, and every inbound email is matched onto one before it reaches your webhook. thread\_id is the handle your code keeps.

Example: an email from marco.lind@lindmetall.de with the subject Prices for 3mm sheet arrives with no In-Reply-To and no References header. It joins thr\_8f2c, the thread of the RFQ it answers, and is marked smart-matched.

### Missing reply headers

A mail client that drops In-Reply-To and References, or a forward written as a new message, can still join the conversation it continues.

### New sender or subject

A colleague answering from their own address or a reply under a rewritten subject stays on the thread.

Example: with thread\_across\_addresses on, nora@yourapp.com sent the RFQ and Marco's answer without reply headers arrived at purchasing@yourapp.com. Both are on thread thr\_8f2c.

### [Across your addresses](https://docs.aiinbx.com/guides/threads#which-thread-incoming-mail-joins)

With thread\_across\_addresses on, mail without reply headers can join a matching thread at any of your addresses. Each space has its own switch.

Example: thread.created fires once for thr\_8f2c. The email.received events for dana@lindmetall.de and marco.lind@lindmetall.de that follow carry the same thread\_id, thr\_8f2c.

### [thread\_id on every event](https://docs.aiinbx.com/webhooks/events/thread-created)

thread.created fires once per conversation, and every email event after it carries the same thread\_id for your app to file the message under.

Example: threads.reply on thr\_8f2c is given only a text. The reply goes from nora@yourapp.com to dana@lindmetall.de under the subject Re: 3mm sheet confirmed, with In-Reply-To and References set from the thread.

### [Replies](https://docs.aiinbx.com/guides/threads#replying)

threads.reply takes the thread and your text. The sender, recipients, subject, In-Reply-To and References come from the conversation.

Console

## Every conversation, message by message

The thread page lists the messages of one conversation with their senders, categories and times, showing the same data the API returns.

The console's thread page shows all four messages of the thread in order, each labelled with its category (out of office, human). Under each smart-matched message it says why it belongs to this thread, such as Marco covering for Dana and Dana confirming the price.

-   In order: What you sent and what came back are one list, oldest first, each message with its direction and category.
-   Why it is on the thread: A message matched without reply headers carries a mark and one line saying why it belongs to this conversation.
-   Answer from the page: Reply, reply all and forward are under the last message, and the composer opens on the thread.

API

## One id from the event to the reply

Every email event carries its thread\_id. File the message under it in your own data, then reply on the thread with the email\_id you were handed.

Step 1, email.received: posted to your webhook.

```
{
  "type": "email.received",
  "data": {
    "email_id": "eml_71ac",
    "thread_id": "thr_8f2c",
    "from": "marco.lind@lindmetall.de"
  }
}
```

Step 2, your handler: recipients, subject and reply headers are set for you.

```
const { thread_id, email_id } = event.data

// Your own record of the conversation, keyed on the thread.
await conversations.append(thread_id, event.data)
const answer = await agent.run(await conversations.read(thread_id))

await aiinbx.threads.reply(thread_id, {
  email_id,
  text: answer,
})
```

Details

## The rest of how threads work

-   Answer one email: Pass email\_id and the reply answers that email, whatever arrives on the thread while your code is working.
-   Reply all: reply\_all writes to everyone on the answered email, as a mail client does. Your own colleagues stay on it.
-   Forwarding: threads.forward sends the whole conversation to someone new as one email, oldest first, with quoted tails and repeated signatures removed.
-   Reading a thread: threads.retrieve returns a conversation with its messages, oldest first.
-   Forwards: A forward opens a thread of its own, and forward\_of on it names the conversation it came from.
-   Spaces: A reply joins a thread in the space it arrived in. Mail between two of your customers is a thread in each of their spaces.

Solutions

## Where it comes in

-   [Inbound email APIReceive email in your app over an API. Point an MX record at AI Inbx or connect Gmail and Outlook, and every message arrives as a signed, parsed JSON webhook.ThreadingAttachmentsMailboxesWildcard domains](/solutions/inbound-email-api)
-   [Email reply parserParse every email reply down to what the sender wrote: quoted text and repeated signatures removed, answers typed inside the quote kept where they were.ThreadingMailboxes](/solutions/email-reply-parser)
-   [Send email APISend email from your domain or your users' own Gmail and Outlook with one API call. Opt-outs and pacing are checked first, and replies land on the thread.ThreadingMailboxesPacingSuppressions](/solutions/send-email-api)
-   [Scheduled email APISchedule an email up to 30 days ahead, then move or cancel it by id until its time comes. It is composed then, so suppressions and threads stay current.ThreadingSending hoursSuppressions](/solutions/scheduled-email-api)
-   [Email open trackingTrack email opens and clicks per domain or per send. Apple privacy prefetches and security scanner clicks arrive flagged as bots, each with its reason.Threading](/solutions/email-open-tracking)

## Give your product an inbox. The hard parts are already handled.

[Get started](/signup)
