Send email from Next.js over SMTP

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.

What are the SMTP settings?

Hostsmtp.unitpost.com
Usernameunitpost(always this literal value)
PasswordYour Unitpost API key(must carry emails:send)
Port (STARTTLS)587(or 2587 if blocked)
Port (implicit TLS)465(or 2465 if blocked)
From addressAny address on a verified domain

How do I set it up?

  1. Install Nodemailer

    Shell
    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 guide — this page is the Next.js wiring.