Concepts
Threads
How email threading works in Mailgent
Mailgent automatically groups related emails into threads using standard email headers (In-Reply-To, References).
How Threading Works
- When you send an email, a new thread is created
- When someone replies, Mailgent matches it to the existing thread via email headers
- When you reply back, it continues the same thread
Thread: thd_a3f91b00c4e2d7e8
├── [sent] You → customer@gmail.com "Hello!"
├── [received] customer@gmail.com → You "Hi, thanks for reaching out"
└── [sent] You → customer@gmail.com "Here's the info you requested"Listing Threads
curl https://api.mailgent.dev/v0/threads \
-H "Authorization: Bearer mgent-your-api-key"Returns threads sorted by most recently updated:
{
"threads": [
{
"threadId": "thd_a3f91b00c4e2d7e8",
"subject": "Hello!",
"messageCount": 3,
"updatedAt": "2026-03-28T14:30:00.000Z"
}
]
}Getting a Full Thread
curl https://api.mailgent.dev/v0/threads/thd_a3f91b00c4e2d7e8 \
-H "Authorization: Bearer mgent-your-api-key"Returns the thread with all messages in chronological order.
Agent Pattern
A typical agent workflow:
1. Poll for new messages: mail.list_messages(labels: "unread")
2. Get thread context: mail.get_thread(threadId: "...")
3. Feed full thread to LLM
4. Reply with LLM response: mail.reply(messageId: "...", text: "...")
5. Mark processed: mail.update_labels(messageId: "...", ...)This gives the agent full conversation context before responding.