# Nuxt

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

Send your first email from a Nuxt app using the `sendping` Node SDK. Install it with `npm install sendping`, then import `SendPing` 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 SendPing [API key](https://www.sendping.co/docs/api-keys/overview).
- A [verified domain](https://www.sendping.co/docs/domains/managing) to send from.

## 1. Install the SDK

```bash
npm install sendping
```

## 2. Add your API key

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

**.env**

```ini
SENDPING_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 { SendPing } from 'sendping';

const mb = new SendPing(process.env.SENDPING_API_KEY!);

export default defineEventHandler(async () => {
  const { data, error } = await mb.emails.send({
    from: 'Acme <onboarding@yourdomain.com>',
    to: ['delivered@test.sendping.co'],
    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.sendping.co/docs/api/emails-send) reference.
