AgentMail is a free, open source email & communication project written in TypeScript and released under MIT. It has 41 GitHub stars, 17 forks and 3 open issues, and was last pushed 5 days ago. On this registry it ranks #13 of 13 tracked projects in Email & Communication, with 5 head-to-head comparisons available. It gained 1 stars over the last 30 tracked days.

What is AgentMail?

AgentMail is a TypeScript client library and inbox API for AI agents and workflows, aimed at developers who need to give agents their own email inboxes rather than route everything through a human mailbox.

What it is

AgentMail is the Agentmail TypeScript library, an SDK published to npm as agentmail that provides convenient access to the Agentmail APIs from TypeScript. It lives in the TypeScript/Node ecosystem and is generated with Fern, which shapes much of its structure: subpackage exports, typed request and response interfaces, configurable environments, and per-request controls such as retries, timeouts, and request abortion.

The concrete problem it solves is the gap between an agent that can reason and an agent that can send and receive mail. Rather than writing raw HTTP calls, handling status codes, and parsing responses by hand, a developer instantiates AgentMailClient with an API key and calls typed methods such as client.inboxes.create(undefined). The library replaces hand-rolled email plumbing and ad hoc inbox handling for agent workloads — the thing it substitutes for is a bespoke integration layer between an agent and an email service, not a mail server itself.

Key capabilities

  • Inbox provisioning through client.inboxes.create(), with list operations typed as AgentMail.ListInboxesRequest.
  • Environment switching via AgentMailEnvironment.Prod so the same client code can point at different API endpoints.
  • Typed request and response interfaces exported under the AgentMail namespace, covering both directions of every call.
  • Structured error handling: non-success status codes throw a subclass of AgentMailError exposing statusCode, message, body, and rawResponse.
  • Binary response support through the BinaryResponse type, consumable as stream(), arrayBuffer(), blob(), or bytes(), with a bodyUsed flag; the README demonstrates saving client.domains.getZoneFile() output to disk.
  • Per-request retries, timeouts, and aborting, plus access to raw response data and logging.
  • Custom fetch support, additional headers, additional query string parameters, and documented runtime compatibility.

Who uses it and how

  • Backend and platform teams building Node.js or TypeScript services where each agent gets an inbox it can act on programmatically.
  • Agent and automation developers who need mail as a first-class tool call rather than a side channel, using the typed client inside an existing worker or service.
  • Teams that need DNS-level control alongside messaging, since the SDK exposes client.domains.getZoneFile() for domain configuration output.
  • Integrations where custom fetch, additional headers, or extra query parameters are required — for example, routing through a proxy or attaching tracing metadata.
  • Projects that must distinguish email failures from other faults, using AgentMailError and its statusCode and rawResponse fields.

Getting started

Install with npm i -s agentmail, then instantiate const client = new AgentMailClient({ apiKey: "YOUR_API_KEY" }) and call methods such as client.inboxes.create(undefined). A full reference for the library is linked from the repository's reference.md.

How it compares

No comparable or competing tools are named in the available facts, so AgentMail stands alone in this registry on the evidence provided. Nothing here establishes how it stacks up against other email APIs or SDKs, and no claim to that effect should be inferred.

When to use it — and when not to

Use it when building TypeScript or Node services that need agents to own inboxes and you are content to call a hosted API, since the SDK targets the Agentmail APIs and selects an environment rather than shipping server components. The README covers only the client library: it documents no database, storage, SMTP setup, or self-hosting path, so anyone who must keep mail on their own infrastructure, or who needs a language other than TypeScript, should look elsewhere. The repository shows 38 stars, 17 forks, and 3 open issues with no topics listed, so the surrounding documentation and community are thin relative to the surface area of the SDK; verify the hosted service's terms and availability before depending on it in production.

project readme (upstream, from github) — read inline

Agentmail TypeScript Library

fern shield npm shield

The Agentmail TypeScript library provides convenient access to the Agentmail APIs from TypeScript.

Table of Contents

Installation

npm i -s agentmail

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

import { AgentMailClient } from "agentmail";

const client = new AgentMailClient({ apiKey: "YOUR_API_KEY" });
await client.inboxes.create(undefined);

Environments

This SDK allows you to configure different environments for API requests.

import { AgentMailClient, AgentMailEnvironment } from "agentmail";

const client = new AgentMailClient({
    environment: AgentMailEnvironment.Prod,
});

Request and Response Types

The SDK exports all request and response types as TypeScript interfaces. Simply import them with the following namespace:

import { AgentMail } from "agentmail";

const request: AgentMail.ListInboxesRequest = {
    ...
};

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.

import { AgentMailError } from "agentmail";

try {
    await client.inboxes.create(...);
} catch (err) {
    if (err instanceof AgentMailError) {
        console.log(err.statusCode);
        console.log(err.message);
        console.log(err.body);
        console.log(err.rawResponse);
    }
}

Binary Response

You can consume binary data from endpoints using the BinaryResponse type which lets you choose how to consume the data:

const response = await client.domains.getZoneFile(...);
const stream: ReadableStream<Uint8Array> = response.stream();
// const arrayBuffer: ArrayBuffer = await response.arrayBuffer();
// const blob: Blob = response.blob();
// const bytes: Uint8Array = response.bytes();
// You can only use the response body once, so you must choose one of the above methods.
// If you want to check if the response body has been used, you can use the following property.
const bodyUsed = response.bodyUsed;
Save binary response to a file
Node.js
ReadableStream (most-efficient)
import { createWriteStream } from 'fs';
import { Readable } from 'stream';
import { pipeline } from 'stream/promises';

const response = await client.domains.getZoneFile(...);

const stream = response.stream();
const nodeStream = Readable.fromWeb(stream);
const writeStream = createWriteStream('path/to/file');

await pipeline(nodeStream, writeStream);
ArrayBuffer
import { writeFile } from 'fs/promises';

const response = await client.domains.getZoneFile(...);

const arrayBuffer = await response.arrayBuffer();
await writeFile('path/to/file', Buffer.from(arrayBuffer));
Blob
import { writeFile } from 'fs/promises';

const response = await client.domains.getZoneFile(...);

const blob = await response.blob();
const arrayBuffer = await blob.arrayBuffer();
await writeFile('output.bin', Buffer.from(arrayBuffer));
Bytes (UIntArray8)
import { writeFile } from 'fs/promises';

const response = await client.domains.getZoneFile(...);

const bytes = await response.bytes();
await writeFile('path/to/file', bytes);
Bun
ReadableStream (most-efficient)
const response = await client.domains.getZoneFile(...);

const stream = response.stream();
await Bun.write('path/to/file', stream);
ArrayBuffer
const response = await client.domains.getZoneFile(...);

const arrayBuffer = await response.arrayBuffer();
await Bun.write('path/to/file', arrayBuffer);
Blob
const response = await client.domains.getZoneFile(...);

const blob = await response.blob();
await Bun.write('path/to/file', blob);
Bytes (UIntArray8)
const response = await client.domains.getZoneFile(...);

const bytes = await response.bytes();
await Bun.write('path/to/file', bytes);
Deno
ReadableStream (most-efficient)
const response = await client.domains.getZoneFile(...);

const stream = response.stream();
const file = await Deno.open('path/to/file', { write: true, create: true });
await stream.pipeTo(file.writable);
ArrayBuffer
const response = await client.domains.getZoneFile(...);

const arrayBuffer = await response.arrayBuffer();
await Deno.writeFile('path/to/file', new Uint8Array(arrayBuffer));
Blob
const response = await client.domains.getZoneFile(...);

const blob = await response.blob();
const arrayBuffer = await blob.arrayBuffer();
await Deno.writeFile('path/to/file', new Uint8Array(arrayBuffer));
Bytes (UIntArray8)
const response = await client.domains.getZoneFile(...);

const bytes = await response.bytes();
await Deno.writeFile('path/to/file', bytes);
Browser
Blob (most-efficient)
const response = await client.domains.getZoneFile(...);

const blob = await response.blob();
const url = URL.createObjectURL(blob);

// trigger download
const a = document.createElement('a');
a.href = url;
a.download = 'filename';
a.click();
URL.revokeObjectURL(url);
ReadableStream
const response = await client.domains.getZoneFile(...);

const stream = response.stream();
const reader = stream.getReader();
const chunks = [];

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  chunks.push(value);
}

const blob = new Blob(chunks);
const url = URL.createObjectURL(blob);

// trigger download
const a = document.createElement('a');
a.href = url;
a.download = 'filename';
a.click();
URL.revokeObjectURL(url);
ArrayBuffer
const response = await client.domains.getZoneFile(...);

const arrayBuffer = await response.arrayBuffer();
const blob = new Blob([arrayBuffer]);
const url = URL.createObjectURL(blob);

// trigger download
const a = document.createElement('a');
a.href = url;
a.download = 'filename';
a.click();
URL.revokeObjectURL(url);
Bytes (UIntArray8)
const response = await client.domains.getZoneFile(...);

const bytes = await response.bytes();
const blob = new Blob([bytes]);
const url = URL.createObjectURL(blob);

// trigger download
const a = document.createElement('a');
a.href = url;
a.download = 'filename';
a.click();
URL.revokeObjectURL(url);
Convert binary response to text
ReadableStream
const response = await client.domains.getZoneFile(...);

const stream = response.stream();
const text = await new Response(stream).text();
ArrayBuffer
const response = await client.domains.getZoneFile(...);

const arrayBuffer = await response.arrayBuffer();
const text = new TextDecoder().decode(arrayBuffer);
Blob
const response = await client.domains.getZoneFile(...);

const blob = await response.blob();
const text = await blob.text();
Bytes (UIntArray8)
const response = await client.domains.getZoneFile(...);

const bytes = await response.bytes();
const text = new TextDecoder().decode(bytes);

Advanced

Subpackage Exports

This SDK supports direct imports of subpackage clients, which allows JavaScript bundlers to tree-shake and include only the imported subpackage code. This results in much smaller bundle sizes.

import { InboxesClient } from 'agentmail/inboxes';

const client = new InboxesClient({...});

Additional Headers

If you would like to send additional headers as part of the request, use the headers request option.

import { AgentMailClient } from "agentmail";

const client = new AgentMailClient({
    ...
    headers: {
        'X-Custom-Header': 'custom value'
    }
});

const response = await client.inboxes.create(..., {
    headers: {
        'X-Custom-Header': 'custom value'
    }
});

Additional Query String Parameters

If you would like to send additional query string parameters as part of the request, use the queryParams request option.

const response = await client.inboxes.create(..., {
    queryParams: {
        'customQueryParamKey': 'custom query param value'
    }
});

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the maxRetries request option to configure this behavior.

const response = await client.inboxes.create(..., {
    maxRetries: 0 // override maxRetries at the request level
});

Timeouts

The SDK defaults to a 60 second timeout. Use the timeoutInSeconds option to configure this behavior.

const response = await client.inboxes.create(..., {
    timeoutInSeconds: 30 // override timeout to 30s
});

Aborting Requests

The SDK allows users to abort requests at any point by passing in an abort signal.

const controller = new AbortController();
const response = await client.inboxes.create(..., {
    abortSignal: controller.signal
});
controller.abort(); // aborts the request

Access Raw Response Data

The SDK provides access to raw response data, including headers, through the .withRawResponse() method. The .withRawResponse() method returns a promise that results to an object with a data and a rawResponse property.

const { data, rawResponse } = await client.inboxes.create(...).withRawResponse();

console.log(data);
console.log(rawResponse.headers['X-My-Header']);

Logging

The SDK supports logging. You can configure the logger by passing in a logging object to the client options.

import { AgentMailClient, logging } from "agentmail";

const client = new AgentMailClient({
    ...
    logging: {
        level: logging.LogLevel.Debug, // defaults to logging.LogLevel.Info
        logger: new logging.ConsoleLogger(), // defaults to ConsoleLogger
        silent: false, // defaults to true, set to false to enable logging
    }
});

The logging object can have the following properties:

  • level: The log level to use. Defaults to logging.LogLevel.Info.
  • logger: The logger to use. Defaults to a logging.ConsoleLogger.
  • silent: Whether to silence the logger. Defaults to true.

The level property can be one of the following values:

  • logging.LogLevel.Debug
  • logging.LogLevel.Info
  • logging.LogLevel.Warn
  • logging.LogLevel.Error

To provide a custom logger, you can pass in an object that implements the logging.ILogger interface.

Custom logger examples

Here's an example using the popular winston logging library.

import winston from 'winston';

const winstonLogger = winston.createLogger({...});

const logger: logging.ILogger = {
    debug: (msg, ...args) => winstonLogger.debug(msg, ...args),
    info: (msg, ...args) => winstonLogger.info(msg, ...args),
    warn: (msg, ...args) => winstonLogger.warn(msg, ...args),
    error: (msg, ...args) => winstonLogger.error(msg, ...args),
};

Here's an example using the popular pino logging library.

import pino from 'pino';

const pinoLogger = pino({...});

const logger: logging.ILogger = {
  debug: (msg, ...args) => pinoLogger.debug(args, msg),
  info: (msg, ...args) => pinoLogger.info(args, msg),
  warn: (msg, ...args) => pinoLogger.warn(args, msg),
  error: (msg, ...args) => pinoLogger.error(args, msg),
};

Custom Fetch

The SDK provides a low-level fetch method for making custom HTTP requests while still benefiting from SDK-level configuration like authentication, retries, timeouts, and logging. This is useful for calling API endpoints not yet supported in the SDK.

const response = await client.fetch("/v1/custom/endpoint", {
    method: "GET",
}, {
    timeoutInSeconds: 30,
    maxRetries: 3,
    headers: {
        "X-Custom-Header": "custom-value",
    },
});

const data = await response.json();

Runtime Compatibility

The SDK works in the following runtimes:

  • Node.js 18+
  • Vercel
  • Cloudflare Workers
  • Deno v1.25+
  • Bun 1.0+
  • React Native

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Frequently asked questions

Is AgentMail free to use?

AgentMail is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does AgentMail do?

Email inbox API built for AI agents and workflows

What is AgentMail written in?

AgentMail is primarily written in TypeScript. Its source is publicly available at https://github.com/agentmail-to/agentmail-node, and it has 41 GitHub stars.