# Express

> Send your first email from an Express route using the mailblastr SDK.

Send your first email from an Express server using the `mailblastr` Node SDK. Install it with `npm install mailblastr`, then import `MailBlastr` and call `mb.emails.send()` inside your route handler.

## Prerequisites

- A MailBlastr [API key](https://www.mailblastr.com/docs/api-keys/overview).
- A [verified domain](https://www.mailblastr.com/docs/domains/managing) to send from.
- Node.js 18 or newer.

## 1. Install the SDK

```bash
npm install mailblastr
```

## 2. Add your API key

**.env**

```ini
MAILBLASTR_API_KEY=mb_xxxxxxxxx
```

## 3. Send email from a route

Instantiate the SDK client once at module scope and call `mb.emails.send()` inside your handler.

**server.ts**

```ts
import express, { Request, Response } from 'express';
import { MailBlastr } from 'mailblastr';

const app = express();
const mb = new MailBlastr(process.env.MAILBLASTR_API_KEY);

app.get('/', async (req: Request, res: Response) => {
  const { data, error } = await mb.emails.send({
    from: 'Acme <onboarding@yourdomain.com>',
    to: ['delivered@example.com'],
    subject: 'hello world',
    html: '<strong>it works!</strong>',
  });

  res.status(error ? 400 : 200).json(error ? { error } : { data });
});

app.listen(3000, () => {
  console.log('Listening on http://localhost:3000');
});
```

> **Note:** A successful call returns the created email's `id`. See the full request body in the [Send an email](https://www.mailblastr.com/docs/api/emails-send) reference.
