Integration guide · SMTP
Send Next.js email with Buzzmark.
Next.js has no mailer of its own, so most apps use Nodemailer on the server. This guide sets up one shared Nodemailer transport for Buzzmark, sends from a Route Handler, and reuses the same settings for Auth.js magic links.
What you need
- A Next.js app using the App Router, deployed somewhere that runs Node.js server code.
- A Buzzmark account. The free plan covers 300 emails a month.
- Access to the DNS of the domain you want to send from.
1. Verify your domain and create a hive
In the Buzzmark dashboard, open Domains, add your domain and publish the
SPF, DKIM, DMARC and Return-Path records it generates. The
SPF, DKIM and DMARC checker shows what is
published. Then create a hive and copy its token. It starts with bzm_srv_, is
shown once, and is both the SMTP username and password.
2. Install Nodemailer and add the token
Run npm install nodemailer, plus npm install -D @types/nodemailer
if you use TypeScript. Add the token and your sender to the environment. Do not give either
a NEXT_PUBLIC_ prefix, which would expose it to the browser.
# .env.local
BUZZMARK_TOKEN=bzm_srv_...
EMAIL_FROM="Acme <hello@acme.com>"
3. Create the transport
Put the transport in one server-only module so every part of the app shares it.
secure: false with requireTLS: true is the correct pair for port
587: the connection starts in plain text and must upgrade with STARTTLS before anything is
sent.
// lib/mailer.ts
import nodemailer from "nodemailer";
export const mailer = nodemailer.createTransport({
host: "smtp.buzzmarkapp.com",
port: 587,
secure: false, // starts plain, then upgrades with STARTTLS
requireTLS: true, // refuse to send if STARTTLS fails
auth: {
user: process.env.BUZZMARK_TOKEN,
pass: process.env.BUZZMARK_TOKEN,
},
});
4. Send from a Route Handler
Nodemailer needs Node.js network APIs, so send from a Route Handler or a Server Action,
not from middleware, the Edge runtime or a Client Component. The from address
must be on your verified domain.
// app/api/welcome/route.ts
import { mailer } from "@/lib/mailer";
export const runtime = "nodejs";
export async function POST(request: Request) {
const { email } = await request.json();
await mailer.sendMail({
from: process.env.EMAIL_FROM,
to: email,
subject: "Welcome to Acme",
text: "Thanks for signing up.",
html: "<p>Thanks for signing up.</p>",
});
return Response.json({ ok: true });
}
5. Auth.js magic links (optional)
Auth.js sends sign-in links through its Nodemailer provider, which takes the same server
settings. It needs a database adapter to store the verification tokens, and Nodemailer
installed as in step 2. In NextAuth v4 the equivalent provider is imported from
next-auth/providers/email and accepts the same server and
from options.
// auth.ts
import NextAuth from "next-auth";
import Nodemailer from "next-auth/providers/nodemailer";
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: /* your database adapter */,
providers: [
Nodemailer({
server: {
host: "smtp.buzzmarkapp.com",
port: 587,
auth: {
user: process.env.BUZZMARK_TOKEN,
pass: process.env.BUZZMARK_TOKEN,
},
},
from: process.env.EMAIL_FROM,
}),
],
});
6. Test it
Start the app and call the route:
curl -X POST localhost:3000/api/welcome -H "Content-Type: application/json" -d '{"email":"you@example.com"}'.
The email should arrive within a few seconds and appear in the hive’s message log in
Buzzmark. You can also call await mailer.verify() once to check the connection
and login without sending anything.
For local development and preview deployments, set BUZZMARK_TOKEN to the
token of a capture hive. Its mail is caught
in a test inbox and never delivered, so preview builds cannot email real users. No code
changes between environments.
The SMTP reference lists every setting, the size limit and each reply code.
Troubleshooting
Why do I get a "wrong version number" or SSL error when connecting?
secure is set to true. That means implicit TLS, which is for port 465. Buzzmark uses port 587 with STARTTLS, so set secure to false. The connection is still encrypted, and requireTLS: true makes Nodemailer refuse to send if it is not.
Why does the build or request fail with "Module not found: net" or a similar error?
The code is running on the Edge runtime, or was imported into a Client Component. Nodemailer needs Node.js network APIs. Send from a Route Handler or Server Action on the Node.js runtime, and never from middleware or browser code.
What does "550 5.7.1" mean?
Buzzmark refused the message and the text after the code gives the reason. Most often the from address is on a domain that is not verified in Buzzmark.
Why does authentication fail with "535" in production but not locally?
The environment variable is missing or different on your host. Check BUZZMARK_TOKEN is set for the production environment, has no surrounding spaces or quotes, and redeploy so the new value is picked up.
Setting up something else? See all integration guides.
Rather not do DNS by hand?
Buzzmark is EU-hosted transactional email that generates your SPF, DKIM, DMARC and Return-Path records, checks them for you and warns you if they ever drift.
Free up to 300 emails a month · No credit card