All solutions
Solutions

Send Email from a Node.js AI Agent

fetch() or the @mailsai/sdk package — your Node agent sends from its own address in minutes.

To send email from a Node.js AI agent, POST JSON to the messages endpoint with fetch — or install @mailsai/sdk from npm for a typed client. The agent sends from its own address with its own reputation, and replies come back as structured webhook events your process can act on.

fetch() is enough

const res = await fetch("https://api.mails.ai/v1/messages", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MAILS_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    agent: "hello",
    to: "user@example.com",
    subject: "Welcome aboard",
    body_text: "Thanks for signing up — reply any time and I will read it.",
  }),
});

Prefer types? npm install @mailsai/sdk gives you the same calls with autocomplete; running an MCP-capable runtime instead of raw Node, use @mailsai/mcp-server and your agent gets send/read as tools with zero glue code.

An address the agent actually owns

Create an agent once and it keeps its address, its thread history, and its sender reputation — no shared From: pool, no borrowed human mailbox. Inbound mail is parsed and injection-scanned before your handler sees it. The free tier covers 3,000 emails and 3,000 inbound replies a month; Pro is $20 a month for 50,000 emails and 50,000 inbound replies.

Frequently asked questions

Is there an npm package?
Yes — @mailsai/sdk (TypeScript SDK) and @mailsai/mcp-server (MCP server for agent runtimes like Claude Code and Cursor) are both live on npm. Both are thin wrappers over the same REST API shown here.
Can I use this with the Vercel AI SDK or OpenAI Agents SDK?
Yes — expose sending as a tool in your framework of choice; the integrations section has step-by-step guides for the Vercel AI SDK, OpenAI Agents SDK, and the Anthropic SDK.
How do replies reach my agent?
Each inbound message is parsed to clean JSON and delivered to your webhook (with polling and SSE streaming at /v1/events as alternatives), already scanned for prompt injection and threaded to the conversation it belongs to.

Explore the product

Give your first agent an inbox

Free covers 3,000 emails and 3,000 inbound replies a month, with no card. Upgrade when your agents get busy.

Get your API key