# Railway

> Deploy an app to Railway that sends your first email using the mailblastr SDK.

[Railway](https://railway.com) lets you focus on building your product instead of managing infrastructure, scaling automatically as you grow. Use the `mailblastr` Node SDK — it works the same on Railway as in any Node.js host. Install it with `npm install mailblastr`.

## Prerequisites

Before you start, you will need:

- 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.
- A [Railway](https://railway.com) account.

## 1. Install the SDK

```bash
npm install mailblastr
```

## 2. Create a Railway project

Create a new project on Railway and deploy a Node.js service (for example, from a GitHub repo or with `railway init` from the [Railway CLI](https://docs.railway.com/develop/cli)).

## 3. Add your API key

In your service's **Variables** tab, add `MAILBLASTR_API_KEY` with your key. Railway injects it into the runtime environment so you never commit the secret.

**Service variable**

```sh
MAILBLASTR_API_KEY=mb_xxxxxxxxx
```

## 4. Send your first email

In a request handler (here, a minimal Node.js HTTP server), instantiate the SDK client and call `mb.emails.send()`.

**index.mjs**

```js
import { createServer } from 'node:http';
import { MailBlastr } from 'mailblastr';

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

createServer(async (_req, res) => {
  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.writeHead(error ? 500 : 200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify(error ? { error } : { data }));
}).listen(process.env.PORT || 3000);
```

## 5. Deploy and verify

Once your deployment finishes, open the deploy URL to send your first email.

> **Warning:** This basic example sends an email each time someone visits the deploy URL, so share the link with discretion.

> **Note:** See the full set of body fields in the [Send an email](https://www.mailblastr.com/docs/api/emails-send) reference.
