---
title: "Send email from Next.js over SMTP"
description: "Nodemailer in an App Router Route Handler."
url: https://www.unitpost.com/guides/smtp/nextjs
section: SMTP
updated: 2026-08-28
---
# Send email from Next.js over SMTP

## Connection settings

- **Host**: smtp.unitpost.com
- **Username**: unitpost (always this literal value)
- **Password**: Your Unitpost API key (must carry emails:send)
- **Port (STARTTLS)**: 587 (or 2587 if blocked)
- **Port (implicit TLS)**: 465 (or 2465 if blocked)
- **From address**: Any address on a verified domain

## Send email from Next.js over SMTP

> Nodemailer in an App Router Route Handler.

Send from a Next.js Route Handler with Nodemailer pointed at Unitpost SMTP. Keep the API key on the server — never in a Client Component.

### 1. Install Nodemailer

```bash
npm install nodemailer
npm install -D @types/nodemailer
```

### 2. Create a Route Handler

Server-only. The `from` address must be on a verified domain.

```typescript
import nodemailer from "nodemailer";
import { NextResponse } from "next/server";

const transporter = nodemailer.createTransport({
  host: "smtp.unitpost.com",
  port: 587,
  secure: false,
  requireTLS: true,
  auth: {
    user: "unitpost",
    pass: process.env.UNITPOST_API_KEY,
  },
});

export async function POST() {
  await transporter.sendMail({
    from: "you@yourdomain.com",
    to: "customer@example.com",
    subject: "Hello from Next.js",
    html: "<p>Sent via SMTP.</p>",
  });
  return NextResponse.json({ ok: true });
}
```

### 3. Verify delivery

Check Activity. Same transport as the Nodemailer (/guides/smtp/nodemailer) guide — this page is the Next.js wiring.

## Related

- [Send email from NestJS over SMTP](https://www.unitpost.com/guides/smtp/nestjs): Nodemailer inside a NestJS provider.
- [Send email from Express over SMTP](https://www.unitpost.com/guides/smtp/express): Nodemailer from an Express route.
- [Send email from Python over SMTP](https://www.unitpost.com/guides/smtp/python): stdlib smtplib — no framework required.
