Email threads are the backbone of multi-turn communication. When a human replies to an agent's email, the reply needs to arrive in the same thread so the agent can maintain context. Here is how this works technically.

How Email Threading Works

Email clients use three headers to link messages into threads:

  • Message-ID: A unique ID assigned to each email
  • In-Reply-To: The Message-ID of the email being replied to
  • References: A list of all Message-IDs in the thread

When Gmail, Outlook, or any email client receives a message with In-Reply-To set, it groups the new message with the original in the same thread view.

Sending a Reply with AgentMailr

POST /v1/inboxes/{id}/reply
{
  "email_id": "eml_abc123",  // The email being replied to
  "text": "Thanks for your message. Here is what I found...",
  "html": "<p>Thanks for your message...</p>"
}

AgentMailr automatically sets the correct In-Reply-To and References headers so the reply appears in the same thread for the recipient.

Receiving Replies

When a human replies to the agent's email, AgentMailr receives the message on your domain's mail server, detects the threading headers, links the reply to the original thread, and fires a webhook. Your agent can then read the thread:

GET /v1/threads/{thread_id}

Building a Conversational Agent

With threading, an agent can:

  1. Send an initial email
  2. Receive a reply from the human
  3. Process the reply with an LLM
  4. Send a follow-up reply in the same thread
  5. Repeat until the task is complete

This is the foundation for agents that handle support tickets, negotiate via email, or conduct research interviews autonomously.