All solutions

Solutions

Send Email from a Node.js AI Agent

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: "sarah",
    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. Pricing is per call: $0.001 per send, $0.002 per inbound, nothing monthly.

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.

Live now

Built for agents.
Self-serve in minutes.

The API is live and self-serve. Drop ~6 lines into your agent and ship.

npmpnpmbunnpx
$ npm install @mailsai/sdk
Live on npm today · @mailsai/sdk + @mailsai/mcp-server