How to block disposable email in Next.js

A step-by-step Next.js signup check for throwaway and undeliverable addresses, plus the same check in Express and without a vendor.

14 min read
In short: Check the address on the server, in the Route Handler or Server Action that receives the signup form. With @arcjet/next 1.15.0, add a validateEmail rule that denies DISPOSABLE, INVALID, and NO_MX_RECORDS, call protect() with the email (using request() in a Server Action), and return a generic error. Run the rule in DRY_RUN mode first, then switch it to LIVE.

What the signup check does

To block disposable email in Next.js, check the address on the server before you create the account. Run the check in the Route Handler or Server Action that receives the form, deny addresses that are disposable, malformed, or on a domain with no mail servers, and return a generic error. Start in dry-run mode, review the results, then enforce.

A disposable email provider is a service that hands out throwaway inboxes, often with no signup of its own. People use them to claim a free trial again, to create accounts in bulk, or to avoid hearing from you. A domain with no MX records (DNS entries that name the servers that accept mail for a domain) publishes no mail servers, which usually means a typo or an unused domain. Requiring an MX record is a signup policy, not a deliverability verdict: without one, a sender can still try the domain's own address record. Both checks have to run on the server, because anything that runs only in the browser can be skipped with a direct POST request.

This guide uses Arcjet. Arcjet is a security SDK that you add to your application code. It runs checks such as bot detection, rate limiting, and email validation inside your request handlers. The examples use @arcjet/next 1.15.0 with the App Router. A later section shows the same check in Express, and another shows how to build it yourself from an open-source list.

The procedure has seven steps:

  1. Install @arcjet/next and set the ARCJET_KEY environment variable.
  2. Define an email rule in DRY_RUN mode.
  3. Call the rule from your Route Handler or Server Action.
  4. Return an error message that helps real users and gives attackers little.
  5. Log the email types that the rule reports.
  6. Test the route with sample addresses.
  7. Switch the rule to LIVE once the logs look right.

Install the SDK and set your key

The SDK is one package, and it reads its key from an environment variable. Install the Next.js adapter:

Terminal window
npm install @arcjet/next@1.15.0

Create a free Arcjet account. In the Arcjet Console, select New actor, enter a name, and then select Create. Copy the Actor key from the actor's page. It starts with ajkey_. The Console also shows a project key that starts with aj_prj_key_, and the SDK can't use that one.

Add the key to .env.local in your project root:

Terminal window
ARCJET_KEY=ajkey_yourkey

Don't prefix the variable with NEXT_PUBLIC_. That prefix bundles the value into client JavaScript. In production, set ARCJET_KEY as a secret in your hosting provider's environment settings.

Define the email rule

Create one Arcjet client in a shared module so the Route Handler and the Server Action use the same rule. The validateEmail rule takes a mode and exactly one of allow or deny. With deny, Arcjet blocks only the types you list.

lib/arcjet.ts
import arcjet, { validateEmail } from "@arcjet/next";
export const aj = arcjet({
key: process.env.ARCJET_KEY!,
rules: [
validateEmail({
// Log only. Change to "LIVE" after you review the results.
mode: "DRY_RUN",
deny: ["DISPOSABLE", "INVALID", "NO_MX_RECORDS"],
}),
],
});

The three types cover the cases this guide is about. DISPOSABLE means the domain belongs to a throwaway inbox service. INVALID means the address fails syntax checks, which the SDK runs locally before it calls the Arcjet API. NO_MX_RECORDS means the domain publishes no MX records, which is a policy choice rather than proof that mail can't arrive. Arcjet treats a DNS timeout as if the domain has MX records, so a slow resolver doesn't block a real user.

Two other types exist. FREE matches free webmail providers such as Gmail and Outlook.com. Most consumer products accept these. If you sell only to businesses, see how to block free email providers on a B2B signup before you add it. NO_GRAVATAR matches addresses with no Gravatar profile, which describes most real people, so treat it as a weak signal for review rather than a reason to deny.

Arcjet builds its disposable check from several public, open-source domain lists, a reviewed exception list for false positives, and a check of the domain's mail servers. That last check flags a domain whose mail servers belong to a known disposable provider, whether or not a list names the domain. For more information about how detection works, see how to detect disposable email addresses.

Check the address in a Route Handler

A Route Handler receives the form as a POST request, so you read the email from the body and pass it to protect() with the request. The email property is required when the client has a validateEmail rule.

app/api/signup/route.ts
import { NextResponse } from "next/server";
import { aj } from "@/lib/arcjet";
const EMAIL_ERROR =
"We couldn't use that email address. Check it for typos or use another one.";
export async function POST(req: Request) {
const body = await req.json().catch(() => null);
const email = typeof body?.email === "string" ? body.email.trim() : "";
if (!email) {
return NextResponse.json(
{ error: "Enter an email address." },
{ status: 400 },
);
}
const decision = await aj.protect(req, { email });
// Log what each email rule found, including rules in DRY_RUN mode.
for (const result of decision.results) {
if (result.reason.isEmail()) {
console.info("signup email check", {
decisionId: decision.id,
state: result.state,
conclusion: result.conclusion,
emailTypes: result.reason.emailTypes,
});
}
}
if (decision.isDenied()) {
if (decision.reason.isEmail()) {
return NextResponse.json({ error: EMAIL_ERROR }, { status: 400 });
}
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
// Create the account and send the confirmation email.
return NextResponse.json({ ok: true });
}

decision.isDenied() returns true only when a rule in LIVE mode denies the request. decision.reason.isEmail() tells you that the email rule caused the denial, and emailTypes lists the types that matched. The log line records the decision ID and the types, not the address, so your logs don't collect personal data you don't need. You can look up the full decision in the Arcjet Console by its ID.

Check the address in a Server Action

A Server Action has no request argument, so call request() from @arcjet/next to get the request data that Arcjet needs, then pass it to protect(). This is the documented pattern in the Arcjet Next.js SDK reference, and it works for every Arcjet feature except sensitive-information detection.

app/signup/actions.ts
"use server";
import { request } from "@arcjet/next";
import { aj } from "@/lib/arcjet";
export type SignupState = { error?: string; ok?: boolean };
export async function signup(
_previous: SignupState,
formData: FormData,
): Promise<SignupState> {
const email = String(formData.get("email") ?? "").trim();
if (!email) return { error: "Enter an email address." };
// Access the request data that Arcjet analyzes.
const req = await request();
const decision = await aj.protect(req, { email });
if (decision.isDenied()) {
if (decision.reason.isEmail()) {
return {
error:
"We couldn't use that email address. Check it for typos or use another one.",
};
}
return { error: "We couldn't complete signup. Try again later." };
}
// Create the account and send the confirmation email.
return { ok: true };
}

The Arcjet docs show Server Actions that throw on a denial, which sends the user to the nearest error boundary. For a form, returning state is a better experience, because the user stays on the page with their input intact. With React 19, read the returned state with useActionState:

app/signup/signup-form.tsx
"use client";
import { useActionState } from "react";
import { signup, type SignupState } from "./actions";
export function SignupForm() {
const [state, formAction, pending] = useActionState<SignupState, FormData>(
signup,
{},
);
return (
<form action={formAction}>
<label htmlFor="email">Email</label>
<input id="email" name="email" type="email" required />
{state.error && <p role="alert">{state.error}</p>}
<button type="submit" disabled={pending}>
Sign up
</button>
</form>
);
}

Add the same logging loop from the Route Handler example to the action while the rule is in DRY_RUN mode.

Return an error that doesn't help attackers

Tell the user that the address didn't work and what they can do, but don't name the rule that matched. A message such as "Disposable addresses aren't allowed" tells someone automating signups to switch to a provider that isn't on the list yet. A generic message forces them to guess.

The generic message in the examples still helps real users. Most real failures are typos, such as a misspelled domain with no mail servers, and "check it for typos" covers that case. Some teams show a typo-specific hint for NO_MX_RECORDS and keep the generic message for DISPOSABLE. That trade-off is reasonable, because a typo hint reveals little that an attacker can use. Whatever you show, record the exact types on the server so that support can explain a rejection when a real user asks.

Keep the HTTP status consistent. Return 400 for every email rejection rather than a different code per type. Don't reveal whether an account already exists for the address. That turns your signup form into a way to discover your users' email addresses.

Roll out in dry-run mode, then live

Run the rule in DRY_RUN mode for a few days of real traffic before you block anyone. In DRY_RUN mode, the rule evaluates every address and reports its result, but the overall decision is always allowed, so no user sees an error.

During that period, read the log lines and the Arcjet Console. Look for the following patterns:

  • Real customers whose addresses matched DISPOSABLE. Public disposable lists contain mistakes, and a privacy-focused forwarding service sometimes appears on them.
  • A share of NO_MX_RECORDS matches that is higher than you expect. That often points to a bug in how your form trims or encodes the address.
  • Signups that matched and then behaved like abuse, such as trial accounts that never confirmed. These tell you what enforcing the rule would have saved.

When the matches look right, change mode to "LIVE" in lib/arcjet.ts and deploy. If you want to enforce one type while you keep watching another, use two validateEmail rules: one in LIVE mode for the types you trust, and one in DRY_RUN mode for the type you're still evaluating.

Test with sample addresses

Test each type with an address that triggers it, and test an address that passes. Run these against your local development server with the rule in either mode, and check the log output.

AddressWhy it's a useful testExpected type
test@mailinator.com

Mailinator is a long-running public disposable inbox service, and its domain appears on the open-source disposable lists.

DISPOSABLE
someone@example.invalid

The .invalid top-level domain is reserved by RFC 2606 and never resolves, so it has no mail servers.

NO_MX_RECORDS
someone.example.comThe address has no @ separator, so it fails syntax checks.INVALID
A mailbox you control

A real address confirms that legitimate signups pass and that your confirmation email arrives.

None

Don't use an example.com address as your passing case. The domain is reserved for documentation and publishes a null MX record, which is a DNS entry that states the domain accepts no mail (RFC 7505). Email checkers differ in how they treat it, so it doesn't prove much either way.

To send a test request to the Route Handler, use curl:

Terminal window
curl -X POST http://localhost:3000/api/signup \
-H "Content-Type: application/json" \
-d '{"email":"test@mailinator.com"}'

In LIVE mode, the response is a 400 with the generic error. In DRY_RUN mode, the response is 200, and the log line shows a DENY conclusion with DISPOSABLE in emailTypes. For automated tests in CI, see testing in the Arcjet docs.

Do the same in Express

Express uses the @arcjet/node adapter, and the rule and the decision handling are the same as in Next.js. Install @arcjet/node 1.15.0 and Express:

Terminal window
npm install @arcjet/node@1.15.0 express

Set ARCJET_KEY in the environment the same way. For local development, the Arcjet Node.js quick start also sets ARCJET_ENV=development in the same file. Then call protect() in the signup route:

import arcjet, { validateEmail } from "@arcjet/node";
import express from "express";
const aj = arcjet({
key: process.env.ARCJET_KEY!,
rules: [
validateEmail({
mode: "DRY_RUN",
deny: ["DISPOSABLE", "INVALID", "NO_MX_RECORDS"],
}),
],
});
const app = express();
app.use(express.json());
app.post("/signup", async (req, res) => {
const email =
typeof req.body?.email === "string" ? req.body.email.trim() : "";
if (!email) {
res.status(400).json({ error: "Enter an email address." });
return;
}
const decision = await aj.protect(req, { email });
if (decision.isDenied() && decision.reason.isEmail()) {
res.status(400).json({
error:
"We couldn't use that email address. Check it for typos or use another one.",
});
return;
}
if (decision.isDenied()) {
res.status(403).json({ error: "Forbidden" });
return;
}
// Create the account and send the confirmation email.
res.json({ ok: true });
});
app.listen(3000);

The dry-run rollout, the logging loop, and the test addresses from the earlier sections apply unchanged.

Block disposable email without Arcjet

You can build a basic version of this check from an open-source domain list and a DNS lookup. The code is short. The work is in keeping it accurate.

The disposable/disposable-email-domains repository publishes a plain-text list that it regenerates from several sources. It had about 109,000 entries when we downloaded it on November 24, 2026. The following module loads the list into memory, matches subdomains through the registrable domain, and checks for MX records with Node.js's built-in resolver:

lib/email-check.ts
import { Resolver } from "node:dns/promises";
import { getDomain } from "tldts";
const LIST_URL =
"https://disposable.github.io/disposable-email-domains/domains.txt";
// Domains you have reviewed and decided to accept despite the list.
const ALLOW = new Set(["improvmx.com", "yandex.net"]);
let disposable = new Set<string>();
export async function refreshDisposableList() {
const res = await fetch(LIST_URL);
if (!res.ok) throw new Error(`List download failed: ${res.status}`);
const lines = (await res.text()).split("\n");
const next = new Set(
lines.map((l) => l.trim().toLowerCase()).filter(Boolean),
);
if (next.size === 0) throw new Error("List download was empty");
disposable = next;
}
const resolver = new Resolver({ timeout: 1500, tries: 1 });
// The host and each parent, down to and including the registrable domain:
// a.b.example.com, b.example.com, example.com. Never a public suffix, so a
// stray "co.uk" or "github.io" entry in the list can't match other people.
function candidates(host: string): string[] {
const registrable = getDomain(host, { allowPrivateDomains: true });
if (!registrable) return [];
const labels = host.split(".");
const out: string[] = [];
for (let i = 0; i < labels.length; i++) {
const candidate = labels.slice(i).join(".");
out.push(candidate);
if (candidate === registrable) break;
}
return out;
}
export async function checkEmail(email: string) {
const at = email.lastIndexOf("@");
if (at < 1 || at === email.length - 1) return "INVALID";
const host = email
.slice(at + 1)
.toLowerCase()
.replace(/\.$/, "");
// The most specific entry wins: an exception for a subdomain stops the
// walk before a listed parent can match.
for (const candidate of candidates(host)) {
if (ALLOW.has(candidate)) break;
if (disposable.has(candidate)) return "DISPOSABLE";
}
try {
const mx = await resolver.resolveMx(host);
// No MX records, or only a null MX ("0 .", RFC 7505), which declares
// that the domain accepts no mail.
const servers = mx.filter((r) => r.exchange !== "" && r.exchange !== ".");
if (servers.length === 0) return "NO_MX_RECORDS";
} catch (err) {
const code = (err as NodeJS.ErrnoException).code;
if (code === "ENOTFOUND" || code === "ENODATA") return "NO_MX_RECORDS";
// Timeouts and resolver errors: allow rather than block a real user.
}
return "OK";
}

getDomain comes from the tldts package, which bundles the Public Suffix List. The Public Suffix List records the suffixes under which anyone can register a name, such as .com, .co.uk, or a hosting platform's github.io. The walk stops at the registrable domain because the public lists contain some public suffixes, and matching one would deny every domain registered under it. allowPrivateDomains includes the private section of the list, such as hosting platforms, for the same reason.

NO_MX_RECORDS is a policy, not proof. The email standard lets a sender fall back to a domain's address record when it has no MX records, but real mail domains publish MX records, so a missing MX is usually a typo or an unused domain. A null MX record is different: it states that the domain accepts no mail. Call refreshDisposableList() at startup and on a schedule, and keep serving the previous list when a download fails.

The two entries in ALLOW are real. When we checked on November 24, 2026, improvmx.com, an email forwarding service, and yandex.net, an infrastructure domain of a large webmail provider, were on that list. Whether to accept them is your decision, which is the point: once you own the list, you own its mistakes.

Running this yourself means you take on the following ongoing work:

  • Refresh the list. New disposable domains appear every day. Arcjet's analysis of the FakeFilter feed found about 230 newly recorded disposable domains in the 30 days to November 24, 2026.
  • Review what changes. A bad upstream commit can add a large webmail domain and block thousands of real users. Diff each update before you apply it, or at least alert on unusually large changes.
  • Maintain an exception list. Every false positive that a customer reports goes into ALLOW, and someone has to decide each one.
  • Merge sources. No single list covers every provider. Combining lists multiplies both coverage and false positives.
  • Catch domains that no list names yet. Some services rotate to a fresh domain every few weeks. In the same Arcjet analysis, 85 of the 176 new domains that had MX records on November 24, 2026 (48%) used only mail servers that belong to known disposable providers. A check on the mail servers matches those without a list entry. A list matches them only after someone reports them.
  • Handle DNS failure. Decide what happens when the resolver is slow or down, and test that path.

For a comparison of the maintenance cost, see open-source disposable email lists compared with Arcjet.

What this check doesn't cover

An email check tells you about the address, not about the person or program that submitted it. It doesn't prove that the user controls the inbox. Only a confirmation email does that. For more information about the difference, see email validation compared with email verification.

It also doesn't stop someone who creates accounts with real addresses on their own domain, or a script that submits thousands of valid addresses. Pair the email rule with bot detection and a rate limit on the same route. Arcjet's protectSignup rule combines all three in one call, and how to protect a React Hook Form from spam shows it in a Next.js Route Handler. For the wider set of controls, see how to prevent fake account creation and how to prevent free trial abuse.

Frequently asked questions

Can I block disposable email with client-side validation?

No. Anything that runs only in the browser can be skipped with a direct POST request, so the check has to run on the server before you create the account.

How do I call Arcjet from a Next.js Server Action?

Import request() from @arcjet/next, call const req = await request() inside the action, and pass the result to aj.protect(req, { email }). Return an error in the action state instead of throwing, so the user keeps their form input.

Should the error message say the address is disposable?

No. Naming the rule tells someone automating signups to switch providers. Show a generic message that asks the user to check for typos or use another address, and log the exact email types on the server.

Which email address can I use to test the rule?

Use an address at mailinator.com, a public disposable inbox service, for DISPOSABLE, an address on a reserved .invalid domain for NO_MX_RECORDS, and a string with no @ sign for INVALID. Use a mailbox you control for the passing case.

Should I block free email providers such as Gmail?

Not on a consumer signup, because that's where most people have their address. Some B2B products flag FREE addresses with a DRY_RUN rule for review rather than denying them.

Does blocking disposable email stop fake accounts?

It removes one cheap option. Scripts can still use real addresses on their own domains, so pair the email rule with bot detection, a rate limit, and a confirmation email.

Application security in your code

Protect your application with Arcjet

Signup protection puts bot detection, a rate limit, and email validation on the one POST that matters.