JavaScript email API: create, send and receive email.
The Mailcycle JavaScript email API creates email addresses, sends and receives email, and reads every message through a typed client with no dependencies. Create an address in one call, await the next message, read it and reply. Mail is stored encrypted and opened in your own process with WebCrypto, so the same code runs on Node.js, Deno, Bun, Cloudflare Workers and in the browser.
- mailcycle-sdk
- Node.js 20 or later
The TypeScript SDK is one way into the Mailcycle email API. Full reference at https://docs.mailcycle.email.
Receive and send email in JavaScript and TypeScript.
Sign in, create an address, wait for a message and answer it. That is the whole loop, and it is the same loop whether the mail is a sign-up code, a customer or a receipt.
- 1Install mailcycle-sdk. Create a free account (no card) and set MAILCYCLE_PHRASE to the twelve-word recovery phrase it shows you.
- 2Create an address with mc.addresses.create(). It receives mail straight away.
- 3Wait for the next message with mc.messages.waitFor(), or take it from a webhook.
- 4Reply with mc.messages.send(), threaded under the original.
Read email in Node.js.
Create an address, await the next email that lands on it, then read the sender, subject, text and attachments from a typed Message. Mail that is already there comes back from list().
- waitFor resolves with the next message, decrypted, within timeoutMs.
- mc.messages.list(inboxId) returns the mail already received.
- Attachments come back as a Uint8Array, opened in your own process.
The whole email API, from TypeScript.
Everything the Mailcycle console can do is in the package: addresses, inbound mail, sending, webhooks, events, API keys and devices.
Create email addresses from TypeScript
mc.addresses.create() mints a new address on a shared domain, or on your own domain from Scale, and it receives mail at once. Give it a prefix and a label sealed on your machine.
Receive email and wait for it
mc.messages.waitFor() listens on the event stream and returns the next matching message, filtered by sender or subject, opened and ready to read. Without a stream it checks every five seconds.
Read and parse incoming email
mc.messages.list() and .attachment() return the sender, subject, plain text, the original HTML, a safe HTML with remote images and trackers removed, and every attachment as bytes.
Send email and reply in the thread
mc.messages.send() sends from an address your account owns, with up to ten files. Pass the message you are answering and the threading headers are filled in.
Inbound email webhooks
Register a URL and every message.received event is POSTed to it, signed with HMAC-SHA256 and retried. verifyWebhookSignature() checks the signature in one line.
A live event stream
mc.events.stream() carries the same events over a WebSocket the moment they happen, and reconnects after a drop. Events carry ids, never content.
Test email verification in Playwright, Vitest and Jest.
Create an address in a beforeEach, fill your sign-up form with Playwright, then await mc.messages.waitFor() and read the one-time code or magic link from message.text. If nothing arrives in time the promise rejects with code timeout, so the test fails with a reason rather than hanging.
- A real address on a real domain, so the mail goes through the same path your users' does.
- One call blocks until the message lands, filtered by subject or sender, with a timeout you set.
- Text, HTML and attachments come back parsed, so pulling out a code or a link is a regular expression.
- Mail received from the moment you start waiting counts, even if it lands before the stream is up.
Handle incoming email in Next.js route handlers, Express, Hono and Cloudflare Workers.
Rather than polling, let the mail come to you. A webhook POSTs each event to your URL the moment it happens, signed so you can prove it came from Mailcycle, and retried if your server is down.
Events carry ids, never content. Fetch the message by id and it is opened in your code, exactly as it would be otherwise. Webhooks are on Operator and above.
Instead of Nodemailer plus an IMAP client.
Nodemailer sends through an SMTP transport you provide, and receiving means adding an IMAP client and a real mailbox, or running an SMTP server of your own and parsing what it accepts with a MIME parser.
This package does both directions over HTTPS with fetch. An address is created on demand, mail is pushed to your webhook or awaited with a promise, and messages come back parsed, with safeHtml ready to render. It has no dependencies, so it works where Node's net module does not, such as Cloudflare Workers.
Sending is built for answering the mail your addresses receive, within your plan's daily limit.
Mail is encrypted the moment it arrives and opened in your TypeScript code.
Each address has a key pair derived from your recovery phrase. Incoming mail is sealed to its public key before anything is written down, and the package derives the private key on your machine to open it.
- Signing in proves you hold the key by answering a challenge, so the phrase never crosses the wire.
- Bodies, attachments, address labels and API key names are all sealed. The server stores ciphertext.
- Mail sealed by one SDK opens in every other, and in the app, because they share one published format.
- The package is checked against Mailcycle's published test vectors, including the cases that must be refused.
- Search runs on your device, where mail is decrypted.
What developers build with the TypeScript SDK.
It runs in Express and Next.js apps, Cloudflare Workers, serverless functions, CLIs and browser tools: anywhere TypeScript code needs an email address of its own.
End-to-end tests for sign-up and login
Verification emails, one-time passcodes, magic links, password resets and invitations, checked by a real test in Playwright, Vitest and Jest.
A support or orders inbox your code answers
Give an address to a queue, read what customers send, and reply from the address they wrote to, threaded under their message.
Receipts, invoices and alerts as data
Point suppliers, monitoring and other services at an address and pull the text and attachments straight into your own records.
An address per customer, job or device
Mint addresses on demand and keep each stream of mail separate, with its own label, and delete one when the job is done.
Building an AI agent? It can have an inbox too, through the Mailcycle MCP server, without writing any TypeScript at all.
JavaScript and TypeScript SDK at a glance.
Maintained by Mailcycle, the team that runs the API.
| Package | mailcycle-sdk |
|---|---|
| Registry | npm |
| Install with | npm, pnpm, Yarn or Bun |
| Needs | Node.js 20 or later |
| Also | Also any runtime with fetch and WebCrypto: Deno, Bun, Cloudflare Workers and browsers. No dependencies. |
| Licence | Apache 2.0, free to use in your own applications |
| API | JSON over HTTPS at api.mailcycle.email |
| Guide | The TypeScript guide in the docs |
| Guides | Send email from TypeScriptReceive email in TypeScript |
What each plan unlocks. Free receives mail. A signed-in session sends from Personal up. API keys and webhooks start at Operator, and sending from an API key at Scale. See pricing.
JavaScript and TypeScript email SDK questions.
The same API in every language you use.
Nine SDKs share one encryption format, so a message created by one opens in all the others.
Give your TypeScript code an email address.
Create an account, create an address, and read what arrives. The free tier needs no card.