Agentmail
Agent inboxes and email synchronization
git clone https://github.com/bijectionhq/agentmail.git
cd agentmail
git checkout 4025c1077f23c52d750201041702c5f9658a3210Bijection repository access is required. Request access.
Description
Agent inboxes and email synchronization
Explore the package README for API concepts, configuration, and examples. Check the Bijection source for adaptation-specific setup.
Review the source and its dependencies before adopting this package. Source availability does not establish npm publication or runtime qualification.
Getting started
- Get the source at the revision above and read its package documentation.
- Check the required Bijection SDK version, dependencies, and external service credentials.
- Follow the package setup instructions and the guide to using components.
- Exercise the component in your deployment according to your project’s verification rules.
Open source
Maintained source: bijectionhq/agentmail. Based on agentmail-to/convex. License: Apache-2.0. Consult the repository for license terms, notices, and contributor attribution.
From the upstream publisher
A Convex component for AgentMail.
Explore the demo ↗Upstream overview
From the upstream package documentation.
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.
Use cases
From the upstream package documentation.
- Build customer support AI agents that need to maintain conversation context across multiple email exchanges with full thread history and message persistence
- Create email-based automation workflows where your Convex mutations need to send emails durably with delivery tracking and status updates
- Develop reactive email interfaces that update in real-time as new messages arrive, using
useQueryto subscribe to inbox changes without polling - Implement label-based email organization for AI agents that categorize and route conversations based on content, urgency, or business logic
- Handle inbound email processing where your AI agent needs to analyze full message content, attachments metadata, and thread context to generate appropriate responses
How it works
From the upstream package documentation.
The component integrates into your Convex app through defineApp().use(agentmail) and creates isolated tables for inboxes, messages, and events. You configure it with environment variables for API credentials and webhook secrets to keep sensitive data out of function logs.
For sending emails, you call agentmail.sendMessage() from mutations which enqueues messages through a workpool action with bounded retries. The return value is an OutboundId that you can query reactively for delivery status updates. Inbound emails arrive via webhook handler mounted in convex/http.ts using agentmail.handleWebhook().
Message persistence happens automatically through Svix-verified webhooks that deduplicate by event_id and store full message bodies, thread relationships, and labels in your Convex database. You can subscribe to threads using listInboundMessages({ threadId }) or query by labels using listThreads({ labels }) for reactive UI updates.
Agent logic runs through callback functions like onMessageReceived that receive both the message and full thread context, allowing your AI to make decisions without additional API calls. The component handles the email infrastructure while your agents focus on processing and responding to conversations.
Upstream package FAQ
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.
Use with agents and CLI
Give your coding agent the component’s source identity and setup guidance.
Help me integrate Agentmail with Bijection.
Read: https://bijection.com/components/agentmail/SKILL.md
Check SDK compatibility and dependency availability.
Follow this project's execution and verification rules.Upstream README.md
View repository ↗Documentation from agentmail-to/convex, recorded October 23, 2026. APIs and setup may differ in the Bijection adaptation.
@agentmail/convex
A Convex component for AgentMail.
AgentMail is a stateful email inbox for AI agents — every message your agent sends or receives is persisted as part of a thread, with labels, full bodies, and history. This component brings that inbox state into your Convex database so your agents and your UI both see it live.
It's the difference between "I built on Resend and rebuilt my own thread/label/draft store on top" and "the inbox already exists; I just useQuery it."
What you get
- Threads as first-class state. Every inbound message persists with its
thread_id,in_reply_to, andreferencesin your Convex DB. Subscribe tolistInboundMessages({ threadId })and watch the thread update reactively. - Full message bodies. Text, HTML, extracted text/HTML, attachments metadata — not just headers or previews.
- Labels. Tag conversations on send (
labels: ["urgent", "support-agent"]) and query threads by label vialistThreads({ labels }). - Durable sending.
sendMessage/replyToMessage/forwardMessageenqueue from a mutation; a workpool action talks to AgentMail with bounded retries. Lifecycle (pending → sent → delivered/bounced/...) is itself a reactive query. - Idempotent webhook ingest. Svix-verified, deduped by
event_id, callbacks dispatched via a separate workpool so a slow user handler can't block inbound mail. - Reactive UI.
useQueryover inbox state — new mail, status changes, thread updates — without polling. - Isolated component. Its own tables (
inboxes,inboundMessages,outboundMessages,events), sandboxed from your app's data.
Install
npm install @agentmail/convex
Wire it into your Convex app:
// convex/convex.config.ts
import { defineApp } from "convex/server";
import agentmail from "@agentmail/convex/convex.config";
const app = defineApp();
app.use(agentmail);
export default app;
Set credentials on your Convex deployment (kept out of mutation args so they don't appear in function logs):
npx convex env set AGENTMAIL_API_KEY your_api_key
npx convex env set AGENTMAIL_WEBHOOK_SECRET whsec_...
# Optional: EU residency
npx convex env set AGENTMAIL_BASE_URL https://api.agentmail.eu/v0
Query threads and messages
The most reactive part of the API. Subscribe from React; new mail appears the instant AgentMail's webhook fires.
// convex/email.ts
import { query } from "./_generated/server";
import { components } from "./_generated/api";
import { v } from "convex/values";
export const listThread = query({
args: { threadId: v.string() },
handler: (ctx, { threadId }) =>
ctx.runQuery(components.agentmail.lib.listInboundMessages, { threadId }),
});
export const listInbox = query({
args: { inboxId: v.string() },
handler: (ctx, { inboxId }) =>
ctx.runQuery(components.agentmail.lib.listInboundMessages, { inboxId }),
});
// React
const messages = useQuery(api.email.listThread, { threadId });
For thread metadata (last message, participants, label set) from AgentMail's remote API:
import { AgentMail } from "@agentmail/convex";
const agentmail = new AgentMail(components.agentmail);
await agentmail.listThreads(ctx, inboxId, { labels: ["urgent"] });
await agentmail.getThread(ctx, inboxId, threadId);
await agentmail.getMessage(ctx, inboxId, messageId);
Send mail (with labels)
import { mutation } from "./_generated/server";
import { components } from "./_generated/api";
import { AgentMail } from "@agentmail/convex";
import { v } from "convex/values";
const agentmail = new AgentMail(components.agentmail);
export const sendHello = mutation({
args: { inboxId: v.string(), to: v.string() },
handler: async (ctx, args) => {
return await agentmail.sendMessage(ctx, args.inboxId, {
to: args.to,
subject: "Hello from my Convex agent",
text: "Hi! This was sent from a Convex mutation.",
labels: ["support-agent", "auto-reply"],
});
},
});
The return value is an OutboundId. Subscribe to it for live delivery status:
const status = useQuery(api.email.sendStatus, { outboundId });
// → { status: "sent" | "delivered" | "bounced" | ..., agentmailMessageId, threadId, errorMessage }
Receive mail
Mount the webhook handler in convex/http.ts:
import { httpRouter } from "convex/server";
import { httpAction } from "./_generated/server";
import { components } from "./_generated/api";
import { AgentMail } from "@agentmail/convex";
const agentmail = new AgentMail(components.agentmail);
const http = httpRouter();
http.route({
path: "/agentmail/webhook",
method: "POST",
handler: httpAction(async (ctx, req) => agentmail.handleWebhook(ctx, req)),
});
export default http;
Register the webhook URL with AgentMail (https://your-deployment.convex.site/agentmail/webhook) and copy the secret into AGENTMAIL_WEBHOOK_SECRET.
React to inbound mail (your agent runs here)
import { internalMutation } from "./_generated/server";
import { components, internal } from "./_generated/api";
import { AgentMail } from "@agentmail/convex";
import { v } from "convex/values";
const agentmail = new AgentMail(components.agentmail, {
onMessageReceived: internal.email.onMessageReceived,
});
export const onMessageReceived = internalMutation({
args: { message: v.any(), thread: v.any(), eventId: v.string() },
handler: async (ctx, args) => {
// Your LLM agent runs here.
await ctx.scheduler.runAfter(0, internal.email.autoReply, {
inboxId: args.message.inbox_id,
messageId: args.message.message_id,
threadId: args.message.thread_id,
text: args.message.text ?? "",
});
},
});
The thread argument carries everything AgentMail knows about the thread at the moment the message landed — labels, participants, message count — so your agent can decide what to do without a follow-up round-trip.
Configuration
new AgentMail(component, options?) accepts an options object. Credentials are read from the Convex deployment's env vars and not accepted here, so they never appear in function logs.
| Option | Env var (component-side) | Default |
|---|---|---|
| — | AGENTMAIL_API_KEY | required |
| — | AGENTMAIL_BASE_URL | https://api.agentmail.to/v0 |
webhookSecret | AGENTMAIL_WEBHOOK_SECRET | required for webhook handler |
retryAttempts | — | 5 |
initialBackoffMs | — | 30000 |
onMessageReceived | — | none |
onEvent | — | none (fires on every event type) |
For EU residency, set AGENTMAIL_BASE_URL=https://api.agentmail.eu/v0.
License
Apache-2.0