Agentmail

Add a persistent email inbox to Convex with reactive queries for AI agents - threads, labels, and messages sync automatically to your database.

Installation

npm install @agentmail/convex

About Agentmail

Agentmail provides a stateful email inbox for AI agents built on Convex. It persists email threads, full message bodies, labels, and delivery status directly in your Convex database with reactive queries. The component handles webhook ingestion, durable sending with retry logic, and provides first-class thread management so you can build email-based AI agents without rebuilding inbox infrastructure.

Benefits

Use cases

how to build AI agent email inbox with persistent threads

AgentMail Convex component provides a stateful email inbox where every message persists with thread_id and labels in your Convex database. Subscribe to listInboundMessages({ threadId }) to watch threads update reactively as new emails arrive.

reactive email queries in Convex without polling

Use useQuery with the AgentMail component to subscribe to inbox state changes in real-time. New mail appears instantly when AgentMail's webhook fires, eliminating the need to poll external email APIs.

durable email sending with retry logic in Convex

Call agentmail.sendMessage() from mutations to queue emails with automatic retries through workpool actions. Track delivery status reactively by subscribing to the returned OutboundId.

handle inbound email webhooks in Convex with deduplication

Mount the webhook handler in convex/http.ts using agentmail.handleWebhook(). Events are automatically deduplicated by event_id and processed through isolated workpools to prevent blocking.

Frequently asked questions

How does AgentMail Convex component store email data?

The AgentMail component creates isolated tables (inboxes, inboundMessages, outboundMessages, events) in your Convex database. All email data including full message bodies, attachments metadata, and thread relationships are stored locally and queryable with standard Convex queries.

Can I query email threads and messages reactively?

Yes, the AgentMail component enables reactive email queries using standard Convex useQuery hooks. Subscribe to listInboundMessages({ threadId }) to watch thread updates in real-time as new messages arrive through webhooks.

How reliable is email sending through this component?

The AgentMail component provides durable email sending through Convex mutations that enqueue messages to workpool actions with bounded retries. Delivery status transitions (pending, sent, delivered, bounced) are tracked as reactive queries you can subscribe to.

What happens when my agent receives an email?

Configure an onMessageReceived callback that fires as an internal mutation when emails arrive. The callback receives both the message and complete thread context, allowing your AI agent to process emails with full conversation history without additional API calls.

Links