# Remix

> Send your first email from a Remix resource route using the mailblastr SDK.

Send your first email from a Remix app using the `mailblastr` Node SDK. Install it with `npm install mailblastr`, then import `MailBlastr` and call `mb.emails.send()`. A Remix [resource route](https://remix.run/docs/en/main/guides/resource-routes) runs only on the server, so your key stays private.

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

**.env**

```ini
MAILBLASTR_API_KEY=mb_xxxxxxxxx
```

## 3. Send email from a resource route

Create a resource route under `app/routes/send.ts`. Instantiate the SDK with the key from `process.env`, call `mb.emails.send()`, and return JSON to the caller.

**app/routes/send.ts**

```ts
import { json } from '@remix-run/node';
import { MailBlastr } from 'mailblastr';

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

export const loader = 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) {
    return json({ error }, 400);
  }

  return json(data, 200);
};
```

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