# Nodemailer (SMTP)

> Send your first email from Node.js with Nodemailer over the MailBlastr SMTP relay.

If you already use [Nodemailer](https://www.npmjs.com/package/nodemailer) in your Node.js app, you can send through MailBlastr without touching the HTTP API. Point the transport at the MailBlastr SMTP relay and authenticate with your API key. Emails sent over SMTP show up in your dashboard and event log just like API sends.

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

Add the `nodemailer` package to your project.

**npm**

```bash
npm install nodemailer
```

**yarn**

```bash
yarn add nodemailer
```

**pnpm**

```bash
pnpm add nodemailer
```

**bun**

```bash
bun add nodemailer
```

## 2. SMTP credentials

Configure the transport with the following credentials:

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Host` | string | No | `smtp.mailblastr.com` |
| `Port` | number | No | `465` (implicit TLS) or `587` (STARTTLS). |
| `Username` | string | No | `mailblastr` |
| `Password` | string | No | Your API key, e.g. `mb_xxxxxxxxx`. |

## 3. Send email using SMTP

Create a transport with these credentials, then send. The `from` address must be on a verified domain.

**index.ts**

```js
import nodemailer from 'nodemailer';

async function main() {
  const transporter = nodemailer.createTransport({
    host: 'smtp.mailblastr.com',
    secure: true,
    port: 465,
    auth: {
      user: 'mailblastr',
      pass: 'mb_xxxxxxxxx',
    },
  });

  const info = await transporter.sendMail({
    from: 'Acme <onboarding@yourdomain.com>',
    to: 'delivered@example.com',
    subject: 'Hello World',
    html: '<strong>It works!</strong>',
  });

  console.log('Message sent: %s', info.messageId);
}

main().catch(console.error);
```

> **Note:** Prefer the HTTP API for richer control (idempotency replay, scheduling, attachments by URL). SMTP is best when you already have a Nodemailer setup. See [Send an email](https://www.mailblastr.com/docs/api/emails-send) for the full HTTP body.
