# Nuxt

> Send your first email from a Nuxt server route using the mailblastr SDK.

Send your first email from a Nuxt app using the `mailblastr` Node SDK. Install it with `npm install mailblastr`, then import `MailBlastr` and call `mb.emails.send()`. A Nuxt [server route](https://nuxt.com/docs/guide/directory-structure/server) keeps the key on the server, where it belongs.

## 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.

## 1. Install the SDK

```bash
npm install mailblastr
```

## 2. Add your API key

Store your key in `.env`. Nuxt reads it server-side from `process.env`.

**.env**

```ini
MAILBLASTR_API_KEY=mb_xxxxxxxxx
```

## 3. Send email from a server route

Create a server route under `server/api/send.ts`. Instantiate the SDK client with the key from `process.env` and call `mb.emails.send()`.

**server/api/send.ts**

```ts
import { MailBlastr } from 'mailblastr';

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

export default defineEventHandler(async () => {
  const { data, error } = await mb.emails.send({
    from: 'Acme <onboarding@yourdomain.com>',
    to: ['delivered@example.com'],
    subject: 'Hello world',
    html: '<strong>It works!</strong>',
  });

  if (error) {
    throw createError({ statusCode: 500, message: 'Error sending email' });
  }

  return data;
});
```

> **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.
