# Send email from Node.js

Install `mailset`, set `MAILSET_KEY`, and `mailset.send()` hands back a receipt. The package has no dependencies, and the same code runs on Node.js, Bun, Deno and Cloudflare Workers.

## Install the TypeScript SDK

npm, pnpm, Bun or Yarn. It’s one ES module with its types inside, so there’s no `@types` package to add.

npm:

```bash
npm install mailset
```

pnpm:

```bash
pnpm add mailset
```

bun:

```bash
bun add mailset
```

yarn:

```bash
yarn add mailset
```

## Send your first email from Node.js

`new Mailset()` reads `MAILSET_KEY` from the environment. `send` takes the message with `deliverBy: '10m'`, so a sign-in code that can’t leave within ten minutes is refused rather than sent late. It answers the receipt’s `id` and `status`, and throws a `MailsetError` when Mailset refuses the message.

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_KEY from the environment.
const mailset = new Mailset();

const sent = await mailset.send({
	from: 'Acme <hello@example.com>',
	to: 'ana@example.org',
	subject: 'Your Acme code',
	text: 'Your code is 123456.',
	html: '<p>Your code is <b>123456</b>.</p>',
	deliverBy: '10m',
});

console.log(sent.id, sent.status);
```

## Delivery events, by framework

Mailset posts what became of each message to a URL on your server. Each framework’s guide has the endpoint, reading the body as text or bytes before anything parses it: Next.js, Express, NestJS and Cloudflare Workers.

- [Send email from Next.js](https://mailset.app/send-email/nextjs)
- [Send email from Express](https://mailset.app/send-email/express)
- [Send email from NestJS](https://mailset.app/send-email/nestjs)
- [Send email from Cloudflare Workers](https://mailset.app/send-email/cloudflare-workers)

## Send from your own domain

Your product sends as your own domain either way. What changes is where your team’s mail lives.

- **Sending only.** Your team’s mail stays at Google, Microsoft or wherever it is now. Mailset asks for DKIM, a bounce host and DMARC, and leaves your MX alone. [Send from a domain whose mail stays elsewhere](https://mailset.app/docs/recipes/sending-only)
- **Mailboxes too.** Your team’s mail moves to Mailset, with a real mailbox for every address on the domain and your product’s email on the same bill. [Set up a domain](https://mailset.app/guide/onboarding)

```bash
mailset domains add example.com --sending
mailset domains apply example.com --sending
mailset domains check example.com
mailset keys create --send --domain example.com --from hello@example.com --name "Acme API"
```

## What the TypeScript SDK’s build checks

Each line comes from the SDK’s own build, which fails when one stops being true.

- **Node.js 20+**: Tested: a real send runs on it (a test)
- **Bun 1.4+**: Tested: a real send runs on it (a test)
- **Deno 2.9+**: Tested: a real send runs on it (a test)
- **Cloudflare Workers**: Compatibility date 2024-01-01, tested (a test)
- **No dependencies**: Nothing else to install beside it (its manifest)
- **Typed throughout**: Types for every command and answer (a test)
- **30 KB**: The whole SDK, minified, as one ES module (the build)

## Where to go from here

- [The TypeScript SDK](https://mailset.app/docs/sdk/typescript): Every task, from the client’s options to errors and retries.
- [Webhooks](https://mailset.app/docs/webhooks): The events Mailset posts about your product’s email, and how to check a request’s signature.
- [Give sign-in codes a deadline](https://mailset.app/docs/recipes/deadlines): Use deliverBy so a code that would arrive late is never sent.
- [Retry without sending twice](https://mailset.app/docs/recipes/retries): Make a send safe to repeat with an idempotency key or a Message-ID.
- [Handle bounces](https://mailset.app/docs/recipes/bounces): Tell a dead address from a full inbox, and keep your list clean.
- [Send many messages at once](https://mailset.app/docs/recipes/batches): Up to 100 messages a request, each with its own answer.

## Product email on every plan

Both include 10,000 emails a month, your product’s and your team’s together. Past that it’s $0.40 per 1,000 with pay as you go. Every plan and price: https://mailset.app/pricing

## Sending from Node.js, asked and answered

### Can I keep using Nodemailer?

Not to send through Mailset. Nodemailer speaks SMTP, and Mailset takes your product’s email over HTTPS, so there’s no server for it to log in to. One `mailset.send()` call does the same job.

### Does it run on Bun, Deno and Cloudflare Workers?

Yes. It needs `fetch` and WebCrypto and nothing else, and a real send is tested on Node.js 20+, Bun 1.4+, Deno 2.9+ and Cloudflare Workers 2024-01-01+.

### Can I load it with require()?

The package is an ES module only, so use `import`. From CommonJS code, `await import('mailset')` loads it.

### Can a browser page send with it?

No. `MAILSET_KEY` can send as your domain, so it stays on a server or in a worker. A page in the browser asks your server, and your server sends.

## Try it on your own domain

7 days free, with everything on. Make a key, run the example above and watch the receipt come back. Start at https://mailset.app/start

---

© 2026 Intenseloop, Inc. Mailset’s site, docs and guides are copyrighted. You may read them and use their code to build with Mailset. Don’t republish them or use them to build a copy of Mailset. Terms: https://mailset.app/terms#content