Back to Blog
/6 min read/By SMTPfast Team

How to Set Up Email for Better Auth: Custom SMTP or an Email API

Better Auth does not send email itself: you give it functions such as sendVerificationEmail and sendResetPassword, and they call your email provider. Call an email API from them, or use Nodemailer with host smtp.smtpfa.st, port 587, username smtpfast and an API key with the email:send scope. Do not await the send, so response times do not show whether an account exists.

better-authauthsmtpnodetutorial
Share:𝕏in

The short answer: Better Auth does not send email itself. You give it functions such as sendVerificationEmail and sendResetPassword, and they call your email provider. Send with an email API, or over SMTP with Nodemailer and these settings:

Host:      smtp.smtpfa.st
Port:      587   (or 2525), STARTTLS
Username:  smtpfast
Password:  an SMTPfast API key with the email:send scope

Either way, do not await the send inside the Better Auth callback, as the Better Auth docs advise, so the response time does not show whether an account exists.

We build SMTPfast. The Better Auth details below come from the Better Auth docs, 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. The from address of every auth email must be on a verified domain.

See Domains for the record list.

Step 2: create an API key

Open API Keys and create a key with only the email:send scope. The same key works for the API and as the SMTP password.

# .env (server only)
SMTPFAST_API_KEY=sf_...

Step 3a: send with the email API

One module holds the send function. It labels the email transactional and sends the links untracked. The SDK retries a failed request with an idempotency key it makes for each call, so a retry does not send twice.

npm install @smtpfast/sdk
// lib/auth-email.ts
import { SMTPfast } from "@smtpfast/sdk";

const smtpfast = new SMTPfast(); // reads SMTPFAST_API_KEY

export async function sendAuthEmail(to: string, subject: string, url: string) {
  await smtpfast.emails.send({
    from: "Acme <[email protected]>",
    to: [to],
    subject,
    html: `<p>${subject}:</p><p><a href="${url}">${url}</a></p>`,
    text: `${subject}:\n${url}`,
    category: "transactional",
    track_clicks: false,
  });
}

category: "transactional" keeps sign-in mail out of marketing opt-outs and leaves out the unsubscribe header. Without it, SMTPfast treats the email as marketing. track_clicks: false sends the link exactly as Better Auth built it.

Step 3b: or send over SMTP with Nodemailer

npm install nodemailer
// lib/auth-email.ts
import nodemailer from "nodemailer";

const transport = nodemailer.createTransport({
  host: "smtp.smtpfa.st",
  port: 587,
  secure: false,      // STARTTLS on 587; SMTPfast has no port 465
  requireTLS: true,
  auth: { user: "smtpfast", pass: process.env.SMTPFAST_API_KEY },
});

export async function sendAuthEmail(to: string, subject: string, url: string) {
  await transport.sendMail({
    from: "Acme <[email protected]>",
    to,
    subject,
    html: `<p>${subject}:</p><p><a href="${url}">${url}</a></p>`,
    text: `${subject}:\n${url}`,
    headers: {
      "X-SMTPfast-Category": "transactional",
      "X-SMTPfast-Track-Clicks": "false",
    },
  });
}

Over SMTP, the two X-SMTPfast- headers do what the category and track_clicks fields do in the API. SMTPfast reads them and removes them before sending.

Step 4: wire it into Better Auth

// lib/auth.ts
import { betterAuth } from "better-auth";
import { magicLink } from "better-auth/plugins";
import { sendAuthEmail } from "./auth-email";

export const auth = betterAuth({
  // database: ...
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: true,
    sendResetPassword: async ({ user, url }) => {
      void sendAuthEmail(user.email, "Reset your password", url).catch(console.error);
    },
  },
  emailVerification: {
    sendOnSignUp: true,
    sendVerificationEmail: async ({ user, url }) => {
      void sendAuthEmail(user.email, "Verify your email address", url).catch(console.error);
    },
  },
  plugins: [
    magicLink({
      sendMagicLink: async ({ email, url }) => {
        void sendAuthEmail(email, "Your sign-in link", url).catch(console.error);
      },
    }),
  ],
});

Both versions of sendAuthEmail take the same arguments. The callbacks return at once and the email goes out in the background, as the Better Auth docs recommend. On a serverless platform the function can stop when the response is sent, so pass the promise to waitUntil (for example from @vercel/functions) or your platform's equivalent instead of void.

The Better Auth docs also note that an error thrown by sendVerificationEmail during sign-up does not stop the sign-up; it is logged. To block sign-ups when email fails, use a user.create.before database hook.

Step 5: test it

  1. Sign up with an address you can read, then request a password reset and a magic link.
  2. In SMTPfast, open Emails: each message shows its status and delivery attempts. To check the category, read the email with GET /v1/emails/{id} (a key with email:read): "category": "marketing" means the label did not arrive.
  3. 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
535 Authentication failed (SMTP) or 401 (API) The SMTP username must be smtpfast and the password the full API key; the key needs email:send.
550 (SMTP) or 403 (API): domain not verified The from address is not on a verified SMTPfast domain.
SMTP connection timeout Port 465 is not open on SMTPfast; use 587 or 2525. Some hosts block outbound SMTP: use the API instead.
451 (SMTP) or 429 (API) Your plan's hourly limit or a first-week stage. The SDK retries a 429; see Rate limits.
No email and no error The send was not awaited and the function stopped first (serverless). Use waitUntil. Errors also only show in your logs, because of the .catch.
Users can request many emails Better Auth's rate limiter is on in production by default (100 requests per 10 seconds, stricter on /sign-in/email) and off in development. Add rules for the routes that send email.
Mail lands in spam Check that SPF, DKIM and DMARC pass for the from domain and that the email has a text part.

Sources

Checked on 22 November 2026:

Other auth guides: Supabase Auth, Clerk, Auth.js / NextAuth and Firebase Authentication.

Frequently asked questions

Does Better Auth have built-in SMTP?

No. Better Auth calls functions you write, such as emailVerification.sendVerificationEmail, emailAndPassword.sendResetPassword and the magic link plugin's sendMagicLink. Inside them you send the email with any provider, over SMTP with Nodemailer or with an email API.

What are the SMTP settings for Better Auth with SMTPfast?

Host smtp.smtpfa.st, port 587 (or 2525) with STARTTLS, username smtpfast, and an SMTPfast API key with the email:send scope as the password. In Nodemailer that is host, port 587, secure false, requireTLS true and auth { user, pass }.

Should I await the email send in Better Auth?

No. Better Auth's docs advise against awaiting it, to prevent timing attacks: a request that waits for an email takes longer than one that does not, which can show whether an address has an account. On serverless platforms, pass the send to waitUntil or a similar function so it finishes after the response.

SMTP or API for Better Auth?

Either works. An API send is one HTTPS request and works where outbound SMTP ports are blocked or in Edge runtimes. SMTP with Nodemailer suits servers that already have a mail setup. With SMTPfast both reach the same sending pipeline; label auth email transactional with the category field (API) or the X-SMTPfast-Category header (SMTP).

Ready to get started?

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

Start free