# NextAuth (SMTP)

> Send NextAuth magic-link and verification emails through MailBlastr over SMTP.

NextAuth's Email provider sends sign-in (magic link) and verification emails over SMTP via Nodemailer. Point it at the MailBlastr SMTP relay and authenticate with your API key so auth emails are delivered and tracked in your dashboard.

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

Install [`next-auth`](https://next-auth.js.org) and [`nodemailer`](https://www.npmjs.com/package/nodemailer) (the Email provider uses Nodemailer under the hood).

**npm**

```bash
npm install next-auth nodemailer
```

**yarn**

```bash
yarn add next-auth nodemailer
```

**pnpm**

```bash
pnpm add next-auth nodemailer
```

**bun**

```bash
bun add next-auth nodemailer
```

## 2. Configure SMTP credentials

Add your MailBlastr SMTP credentials to your application's `.env` file. The `EMAIL_FROM` address must be on a verified domain.

**.env**

```ini
EMAIL_SERVER_USER=mailblastr
EMAIL_SERVER_PASSWORD=mb_xxxxxxxxx
EMAIL_SERVER_HOST=smtp.mailblastr.com
EMAIL_SERVER_PORT=465
EMAIL_FROM=onboarding@yourdomain.com
```

## 3. Configure the Email provider

In your `[...nextauth].js` file (typically under `pages/api/auth`), configure the Email provider with the SMTP settings from your environment.

**[...nextauth].ts**

```js
import NextAuth from 'next-auth';
import EmailProvider from 'next-auth/providers/email';

export default NextAuth({
  providers: [
    EmailProvider({
      server: {
        host: process.env.EMAIL_SERVER_HOST,
        port: process.env.EMAIL_SERVER_PORT,
        auth: {
          user: process.env.EMAIL_SERVER_USER,
          pass: process.env.EMAIL_SERVER_PASSWORD,
        },
      },
      from: process.env.EMAIL_FROM,
    }),
    // ... other providers as needed
  ],
  // ... any other NextAuth.js configs
});
```

> **Note:** Set `EMAIL_SERVER_PORT=587` to use STARTTLS instead of implicit TLS on port `465`.
