Add email capabilities to your TypeScript AI agents with MultiMail's API. Send, read, and reply to email with configurable human oversight.
The Vercel AI SDK is a TypeScript-first toolkit for building AI applications. Its tool system lets you define typed functions that LLMs can call, making it straightforward to add email capabilities through MultiMail's REST API.
MultiMail gives your Vercel AI SDK agents a complete email backend: sending, receiving, replying, thread tracking, and contact management. The default gated_send oversight mode means your agent composes emails but delivery waits for human approval, which fits naturally into the AI SDK's streaming UI patterns.
Whether you are building a Next.js chatbot that handles customer email or a standalone agent that manages an inbox, the combination of Vercel AI SDK's type-safe tools and MultiMail's email API provides a production-ready foundation.
Both the Vercel AI SDK and MultiMail's API are TypeScript-friendly. Define email tools with Zod schemas for full type safety, and get structured responses you can render directly in your UI.
The Vercel AI SDK supports streaming tool calls. Your agent can stream its reasoning while making MultiMail API calls, showing users the email being composed in real time before it enters the approval queue.
MultiMail's gated_send mode pairs well with the AI SDK's UI components. Show users a preview of the composed email and let them approve it through your app's interface or the MultiMail dashboard.
The Vercel AI SDK runs on edge runtimes. MultiMail's REST API is edge-compatible with no Node.js-specific dependencies, so your email-capable agent works in serverless and edge environments.
MultiMail returns structured JSON from every endpoint. The AI SDK can parse these into typed objects, letting your agent reason about inbox contents, thread history, and contact data with full type information.
import { generateText, tool } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';
const MULTIMAIL_API = 'https://api.multimail.dev/v1';
const headers = {
'Authorization': 'Bearer mm_live_your_api_key',
'Content-Type': 'application/json',
};
const sendEmail = tool({
description: 'Send an email. In gated_send mode, the email is queued for human approval.',
parameters: z.object({
mailbox_id: z.string().describe('The mailbox to send from'),
to: z.string().email().describe('Recipient email address'),
subject: z.string().describe('Email subject line'),
body: z.string().describe('Email body content'),
}),
execute: async ({ mailbox_id, to, subject, body }) => {
const resp = await fetch(`${MULTIMAIL_API}/send`, {
method: 'POST',
headers,
body: JSON.stringify({ mailbox_id, to, subject, body }),
});
return resp.json();
},
});
const checkInbox = tool({
description: 'Check a mailbox inbox for recent emails.',
parameters: z.object({
mailbox_id: z.string().describe('The mailbox to check'),
limit: z.number().optional().default(10),
}),
execute: async ({ mailbox_id, limit }) => {
const resp = await fetch(
`${MULTIMAIL_API}/mailboxes/${mailbox_id}/inbox?limit=${limit}`,
{ headers }
);
return resp.json();
},
});Create type-safe MultiMail tools using the Vercel AI SDK's tool function and Zod for parameter validation.
const result = await generateText({
model: openai('gpt-4o'),
tools: { sendEmail, checkInbox, replyEmail },
maxSteps: 5,
system: `You are an email assistant. You can send emails, check inboxes,
and reply to messages. The mailbox uses gated_send mode, so all
outgoing emails are queued for human approval before delivery.
Mailbox ID: mbx_main`,
prompt: 'Check my inbox and draft a reply to any unanswered emails.',
});
console.log(result.text);Use generateText with tools to create an agent that can send and read email.
"cm">// app/api/chat/route.ts
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: openai('gpt-4o'),
tools: { sendEmail, checkInbox, replyEmail, getThread },
maxSteps: 5,
system: `You are an email assistant for the user's MultiMail account.
Always confirm the recipient and subject before sending.
The mailbox uses gated_send mode — emails need approval.`,
messages,
});
return result.toDataStreamResponse();
}Create an API route that streams AI responses with email tool capabilities.
const getThread = tool({
description: 'Get all messages in an email thread for context.',
parameters: z.object({
thread_id: z.string().describe('The thread ID to retrieve'),
}),
execute: async ({ thread_id }) => {
const resp = await fetch(
`${MULTIMAIL_API}/threads/${thread_id}`,
{ headers }
);
return resp.json();
},
});
const replyEmail = tool({
description: 'Reply to an email within its thread.',
parameters: z.object({
message_id: z.string().describe('The message ID to reply to'),
body: z.string().describe('Reply body content'),
}),
execute: async ({ message_id, body }) => {
const resp = await fetch(`${MULTIMAIL_API}/reply`, {
method: 'POST',
headers,
body: JSON.stringify({ message_id, body }),
});
return resp.json();
},
});Add thread retrieval and reply capabilities to your email agent.
Sign up at multimail.dev, create a mailbox, and generate an API key. Your key starts with mm_live_.
Install the Vercel AI SDK and your preferred model provider.
npm install ai @ai-sdk/openai zodCreate tool definitions using the AI SDK's tool function with Zod schemas for parameters. Implement the execute function to call MultiMail's REST API.
Use generateText or streamText with your email tools and a system prompt that explains the mailbox context and oversight mode.
const result = await generateText({
model: openai(&"cm">#039;gpt-4o'),
tools: { sendEmail, checkInbox },
maxSteps: 5,
prompt: &"cm">#039;Check my inbox',
});In gated_send mode, inform users when emails are pending approval. Optionally build approval UI in your app or direct users to the MultiMail dashboard.
Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a 38-tool MCP server. Formally verified in Lean 4.