Back to Blog
/6 min read/By SMTPfast Team

How to Set Up the Auth.js (NextAuth) Email Provider With Custom SMTP

Add the Nodemailer provider from next-auth/providers/nodemailer, set server to host smtp.smtpfa.st, port 587, user smtpfast and an SMTPfast API key with the email:send scope, and set from to an address on your verified domain. The email provider needs a database adapter for its tokens. Override sendVerificationRequest to label the sign-in email transactional.

nextauthauthjsauthsmtpnextjstutorial
Share:𝕏in

The short answer: add the Nodemailer provider to Auth.js (NextAuth v5) and point its server at your SMTP provider. With SMTPfast:

Nodemailer({
  server: {
    host: "smtp.smtpfa.st",
    port: 587,            // or 2525; STARTTLS, no port 465
    requireTLS: true,
    auth: { user: "smtpfast", pass: process.env.SMTPFAST_API_KEY },
  },
  from: "Acme <[email protected]>",
})

The password is an SMTPfast API key with the email:send scope, and from must be on a domain you verified in SMTPfast. Auth.js needs a database adapter for any email provider, because it stores the sign-in tokens.

We build SMTPfast. The Auth.js details below come from the Auth.js docs and the provider's source, checked on 22 November 2026; the links are at the end.

Step 1: verify your sending domain

  1. In SMTPfast, open Domains and add the domain you will send from, for example auth.yourdomain.com.
  2. Publish the records SMTPfast shows: three DKIM CNAME records, an SPF TXT record, a DMARC TXT record, and an MX and a TXT record for the bounce. subdomain. On Cloudflare, Connect Cloudflare adds them for you.
  3. Click Verify Now and wait for the domain to show as verified.

See Domains.

Step 2: create an API key

Open API Keys in SMTPfast and create a key with only the email:send scope. It is the SMTP password.

# .env.local
AUTH_SECRET=...            # npx auth secret
SMTPFAST_API_KEY=sf_...
EMAIL_FROM="Acme <[email protected]>"

Step 3: add the provider

Install Nodemailer; Auth.js does not include it:

npm install nodemailer
// auth.ts
import NextAuth from "next-auth";
import Nodemailer from "next-auth/providers/nodemailer";
import { createTransport } from "nodemailer";
import { PrismaAdapter } from "@auth/prisma-adapter"; // or any Auth.js adapter
import { prisma } from "@/lib/prisma";

export const { handlers, auth, signIn, signOut } = NextAuth({
  adapter: PrismaAdapter(prisma),
  providers: [
    Nodemailer({
      server: {
        host: "smtp.smtpfa.st",
        port: 587,
        requireTLS: true,
        auth: { user: "smtpfast", pass: process.env.SMTPFAST_API_KEY },
      },
      from: process.env.EMAIL_FROM,
      async sendVerificationRequest({ identifier, url, provider }) {
        const { host } = new URL(url);
        const transport = createTransport(provider.server);
        const result = await transport.sendMail({
          to: identifier,
          from: provider.from,
          subject: `Sign in to ${host}`,
          text: `Sign in to ${host}\n${url}\n`,
          html: `<p>Sign in to ${host}</p><p><a href="${url}">Sign in</a></p>`,
          headers: {
            "X-SMTPfast-Category": "transactional",
            "X-SMTPfast-Track-Clicks": "false",
          },
        });
        const failed = [...(result.rejected ?? []), ...(result.pending ?? [])];
        if (failed.length) throw new Error(`Email (${failed.join(", ")}) could not be sent`);
      },
    }),
  ],
});

This sendVerificationRequest is a short version of the default one in the Auth.js source: the same transport, recipient, sender, subject and error check, with a plain template and two headers added. The default template also follows your Auth.js theme and avoids making the host name a link; copy it from the source if you want those. The headers:

  • X-SMTPfast-Category: transactional labels the sign-in email transactional. Without it, SMTPfast treats the email as marketing: it gets a one-click unsubscribe header, and a recipient who unsubscribed from your marketing email would not get the link.
  • X-SMTPfast-Track-Clicks: false sends the link exactly as Auth.js built it, without click tracking.

SMTPfast reads both headers and removes them before sending. If you keep the default sendVerificationRequest, sign-in still works; the email is then marketing and follows your account's tracking settings.

The sign-in form calls the provider by its id:

// app/login/page.tsx
import { signIn } from "@/auth";

export default function Login() {
  return (
    <form action={async (formData) => { "use server"; await signIn("nodemailer", formData); }}>
      <input type="email" name="email" placeholder="[email protected]" required />
      <button type="submit">Email me a sign-in link</button>
    </form>
  );
}

Without SMTP: the HTTP email provider

Auth.js also takes a custom email provider: an object with type: "email" and your own sendVerificationRequest. Use it to call an email API instead of opening an SMTP connection, for example where outbound SMTP ports are blocked:

import { SMTPfast } from "@smtpfast/sdk";
const smtpfast = new SMTPfast();

// in providers: [...]
{
  id: "http-email",
  name: "Email",
  type: "email",
  maxAge: 60 * 60 * 24,
  async sendVerificationRequest({ identifier, url }) {
    await smtpfast.emails.send({
      from: process.env.EMAIL_FROM!,
      to: [identifier],
      subject: "Your sign-in link",
      html: `<p><a href="${url}">Sign in</a></p>`,
      text: `Sign in: ${url}`,
      category: "transactional",
      track_clicks: false,
    });
  },
}

The form then calls signIn("http-email", formData).

Step 4: test it

  1. Start the app, open the sign-in form and enter an address you can read.
  2. In SMTPfast, open Emails to see the message, its status and its delivery attempts.
  3. Click the link: you land signed in, and the adapter's session table has a new row.
  4. Open the original message in the inbox and check that SPF, DKIM and DMARC pass, or paste the headers into the email header analyzer.

Common errors

What you see Cause and fix
MissingAdapter error Email providers need a database adapter. Add one to NextAuth({ adapter }).
Nodemailer requires a server configuration server is missing or undefined, often an unset environment variable.
535 Authentication failed The user must be exactly smtpfast, the password the full API key with email:send.
550 Domain ... is not verified from is not on a verified SMTPfast domain.
Connection timeout or ECONNREFUSED on 465 SMTPfast has no port 465. Use 587 or 2525 with requireTLS: true and secure: false (the default).
451 with a limit message Your plan's hourly limit or a first-week stage. See Rate limits. The Auth.js docs describe no rate limit for sign-in emails, so add one to the sign-in form.
The link says it expired or is invalid A mail scanner or link preview opened it first, or the token's maxAge (24 hours by default) passed.
Mail lands in spam Check that SPF, DKIM and DMARC pass for the from domain.

Sources

Checked on 22 November 2026:

Other auth guides: Supabase Auth, Clerk, Better Auth and Firebase Authentication.

Frequently asked questions

How do I use custom SMTP with Auth.js or NextAuth?

Use the Nodemailer provider (next-auth/providers/nodemailer) and install nodemailer yourself, since Auth.js does not include it. Pass server with your SMTP host, port and credentials, and from with your sender address. With SMTPfast: host smtp.smtpfa.st, port 587, user smtpfast and an API key with the email:send scope as the password.

Does the Auth.js email provider need a database?

Yes. The magic link tokens are stored, so Auth.js needs a database adapter for any email provider. Its docs say it is not possible to enable an email provider without a database.

Can I use an email API instead of SMTP with Auth.js?

Yes. Auth.js has providers for several email APIs, and a custom HTTP email provider: an object with type email and your own sendVerificationRequest function that calls any API.

Which environment variables does the Nodemailer provider use?

The Auth.js examples use EMAIL_SERVER (an SMTP connection string) and EMAIL_FROM, or EMAIL_SERVER_HOST, EMAIL_SERVER_PORT, EMAIL_SERVER_USER and EMAIL_SERVER_PASSWORD. You read them yourself in the provider config.

Ready to get started?

Start sending transactional email today. Free to start, no credit card required.

Start free