Skip to content
NewA free test that shows whether your emails will reach the inbox.
Get started
GuideRun end to end with Better Auth 1.7.28, 6 min read

Send Better Auth emails from your own domain

Runearc sends Better Auth's emails from your own domain. Write one sendEmail helper that posts to Runearc's REST API with fetch, then call it from five callbacks: sendVerificationEmail, sendResetPassword, sendMagicLink, sendVerificationOTP and sendInvitationEmail. There is no extra package to install, and the code below ran against Better Auth 1.7.28.

.env
RUNEARC_API_KEY=mb_live_xxxxxxxxx   # Sending only key
EMAIL_FROM="Acme <auth@acme.com>"   # verified domain
BETTER_AUTH_URL=https://acme.com
Terminal output of the Better Auth run: sign up, password reset, magic link, sign in code and organization invitation each produce an email that arrives, the verification link is left untracked and opening it verifies the user, and Runearc's send log lists the five emails with their tags
This page's auth.ts and email.ts, run unchanged on November 25, 2026 with better-auth 1.7.28 against a local Runearc stack that relays to a local test mailbox. The script called each Better Auth endpoint, checked the email arrived and opened the verification link. The test domain is acme-auth.test; the key is masked.

Which callback sends which email

Better Auth never sends email itself. It calls these functions, and each one calls sendEmail.

  • emailVerification.sendVerificationEmail

    Email verification

    Gets user, url and token. Runs on sign up with sendOnSignUp, and on sign in when requireEmailVerification blocks an unverified user.
  • emailAndPassword.sendResetPassword

    Password reset

    Gets user and url when someone calls requestPasswordReset.
  • magicLink({ sendMagicLink })

    Magic link

    Gets email and url. The link works once and expires after 5 minutes by default.
  • emailOTP({ sendVerificationOTP })

    Sign in and verification codes

    Gets email, otp and a type: sign-in, email-verification, forget-password or change-email.
  • organization({ sendInvitationEmail })

    Organization invitations

    Gets the invitation id, email, organization and inviter. You build the accept link to your own page.

Set up

Three steps before any code.

  1. 1

    Verify your domain

    The from address must be on a domain verified in your Runearc workspace. The records and checks are in the domains docs.
  2. 2

    Create a Sending only key

    It can send and read the send log, and nothing else. Keep it in server env vars, never in client code.
  3. 3

    Set three env vars

    RUNEARC_API_KEY, EMAIL_FROM and BETTER_AUTH_URL, locally and in your host's settings.

One sendEmail helper

Every Better Auth email goes through one function that posts to POST /v1/emails. It sends both a text and an HTML part, tags each email with its kind so you can filter the send log, and throws with Runearc's error code, message and fix when a send is refused. Links get data-runearc-track="false", so click tracking never wraps a one time link, and names that users typed are escaped before they go into HTML.

// One helper for every Better Auth email. It calls Runearc's REST API with fetch.
const API = process.env.RUNEARC_API_URL ?? "https://api.runearc.com/v1";
const FROM = process.env.EMAIL_FROM ?? "Acme <auth@acme.com>"; // on a domain verified in Runearc

type AuthEmail = {
  to: string;
  subject: string;
  text: string;
  html: string;
  kind: string; // saved as a tag, so the send log can be filtered by email type
};

export async function sendEmail({ to, subject, text, html, kind }: AuthEmail) {
  const res = await fetch(`${API}/emails`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.RUNEARC_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ from: FROM, to, subject, text, html, tags: [{ name: "auth", value: kind }] }),
  });
  const body = await res.json();
  // Errors come back as { error: { code, message, fix } }; the fix says what to change.
  if (!res.ok) throw new Error(`Runearc ${res.status} ${body.error.code}: ${body.error.message}. ${body.error.fix ?? ""}`);
  return body as { id: string };
}

// The text and HTML of a one link email. The link is marked so it is not rewritten for click tracking.
export function linkEmail(intro: string, label: string, url: string) {
  return {
    text: `${intro}\n\n${label}: ${url}\n\nIf you did not ask for this, ignore this email.`,
    html:
      `<p>${escapeHtml(intro)}</p>` +
      `<p><a href="${escapeHtml(url)}" data-runearc-track="false">${escapeHtml(label)}</a></p>` +
      `<p>If you did not ask for this, ignore this email.</p>`,
  };
}

// Names and organization names come from users; escape them before they go into HTML.
export function escapeHtml(s: string) {
  return s.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
}

Tested with better-auth 1.7.28 and TypeScript 6.0.3. RUNEARC_API_URL is optional; we set it to point at the local stack.

Wire it into each callback

Keep your database adapter and other options as they are, and add the callbacks you use. Leave out a plugin you do not need. advanced.backgroundTasks tells Better Auth to run the verification, reset, OTP and invitation callbacks after the response: the timing then shows nothing about which accounts exist, and a failed send is logged rather than failing the request.

import { betterAuth } from "better-auth";
import { emailOTP, magicLink, organization } from "better-auth/plugins";
import { linkEmail, sendEmail } from "./email.js";

const OTP_SUBJECT = {
  "sign-in": "Your sign in code",
  "email-verification": "Your verification code",
  "forget-password": "Your password reset code",
  "change-email": "Confirm your new email address",
} as const;

export const auth = betterAuth({
  // database: your adapter (Drizzle, Prisma, Kysely or a pg Pool), unchanged.
  emailAndPassword: {
    enabled: true,
    requireEmailVerification: true,
    sendResetPassword: async ({ user, url }) => {
      await sendEmail({
        to: user.email,
        subject: "Reset your password",
        kind: "reset-password",
        ...linkEmail("Someone asked to reset the password for your account.", "Reset your password", url),
      });
    },
  },
  emailVerification: {
    sendOnSignUp: true,
    sendVerificationEmail: async ({ user, url }) => {
      await sendEmail({
        to: user.email,
        subject: "Verify your email address",
        kind: "verify-email",
        ...linkEmail("Confirm this address to finish signing up.", "Verify your email", url),
      });
    },
  },
  plugins: [
    magicLink({
      sendMagicLink: async ({ email, url }) => {
        await sendEmail({
          to: email,
          subject: "Your sign in link",
          kind: "magic-link",
          ...linkEmail("Use this link to sign in. It works once and expires in 5 minutes.", "Sign in", url),
        });
      },
    }),
    emailOTP({
      sendVerificationOTP: async ({ email, otp, type }) => {
        await sendEmail({
          to: email,
          subject: OTP_SUBJECT[type],
          kind: `otp-${type}`,
          text: `Your code is ${otp}. It expires in 5 minutes.`,
          html: `<p>Your code is <strong>${otp}</strong>. It expires in 5 minutes.</p>`,
        });
      },
    }),
    organization({
      sendInvitationEmail: async ({ id, email, organization, inviter }) => {
        const url = `${process.env.BETTER_AUTH_URL}/accept-invitation/${id}`;
        await sendEmail({
          to: email,
          subject: `Join ${organization.name}`,
          kind: "invitation",
          ...linkEmail(`${inviter.user.name} invited you to join ${organization.name}.`, "Accept the invitation", url),
        });
      },
    }),
  ],
  advanced: {
    // Send after the response, so response time does not show whether an account exists.
    // On Vercel or Cloudflare Workers, pass their waitUntil here instead.
    backgroundTasks: { handler: (task) => void task },
  },
});

Typechecked and run with better-auth 1.7.28 and TypeScript 6.0.3.

The accept page for invitations is yours: read the id from the URL and call authClient.organization.acceptInvitation. The full request and response of the send call, and scheduling, are in the Emails API docs.

A real run

On November 25, 2026 we ran this page's two files unchanged with better-auth 1.7.28 and TypeScript 6.0.3 against a local Runearc stack whose outbound mail went to a local test mailbox. A script called Better Auth's own endpoints: signUpEmail, requestPasswordReset, signInMagicLink, sendVerificationOTP and, after signing in, createOrganization and createInvitation. Each email arrived within a second. Opening the link from the verification email returned HTTP 302 and set emailVerified to true, and Runearc's send log listed the five emails with their tags. On the same stack, a link without data-runearc-track was rewritten for click tracking and the marked one was not. The capture is at the top of this page. Before emailing real users, send one message to the email deliverability test.

What it does not do

  • It does not write your templates. The snippets send short plain emails. Put your own HTML in the helper, or send a Runearc template by id.
  • It does not change Better Auth's rules. Token lifetimes, rate limits and who may invite whom stay in your Better Auth config.
  • The magic link callback is not run in the background. Better Auth awaits sendMagicLink directly, so a refused send fails that request with an error, which the user sees.
  • It needs a verified domain. Until the from address's domain is verified, every send is refused with sender_not_verified, so real users would get nothing.
  • Opens are still counted. The marked links are left alone, but the open pixel is added while open tracking is on. Turn it off in Settings, Tracking if you do not want it on auth email.
  • Plan limits apply. Auth emails count toward the month's sends: 3,000 on the free plan.

If an email does not arrive

Nothing sent, nothing in the log
Background callbacks only log failures. Look in your server log for Failed to run background task and the Runearc error after it.
403 sender_not_verified
EMAIL_FROM is not on a verified domain of the key's workspace. The error's fix field names the next step.
401 invalid_api_key
RUNEARC_API_KEY is missing where the server runs, so the header reads Bearer undefined. Set it and restart the server.
The email stops when the function ends
On serverless platforms, pass the platform's waitUntil to advanced.backgroundTasks.handler, so the send finishes after the response.
The link opens a page that says it expired
A mail scanner may have opened it first, or the token timed out. Check the link is marked untracked, and raise expiresIn if users are slow. Every error code is on the errors page.

On Supabase instead? Supabase Auth custom SMTP needs no code. Sending your app's other mail from a Next.js app is in the Next.js guide, and every tool is in the integrations directory.

Questions

Do I need a Runearc package?

No. The helper uses the global fetch, which Node.js 18 and later, Bun, Deno and edge runtimes all have. The Runearc Node SDK is not on npm yet; when it is, it calls the same endpoint.

Should the callbacks await the send?

Await it inside the callback, and set advanced.backgroundTasks so Better Auth runs the callback after the response. Then the response time does not show whether an account exists, and a failed send is logged instead of failing the request. On Vercel or Cloudflare Workers, pass their waitUntil so the send finishes before the function stops.

Can I send over SMTP instead of the API?

Yes. Point Nodemailer at smtp.runearc.com, port 465 or 587, with the username runearc and an API key as the password, and keep the same callbacks. SMTP sends go through the same checks and show in the same send log, but links in them are never rewritten for click tracking.

What about change email and delete account emails?

They work the same way. user.changeEmail.sendChangeEmailConfirmation and user.deleteUser.sendDeleteAccountVerification receive a user and a url; call sendEmail from them like the verification callback.

Can I keep my email templates in Runearc instead of in code?

Yes. POST /v1/emails takes a template id and variables instead of html and text, so the helper can send a template such as password-reset with the URL as a variable. The templates docs cover the format.

How is this different from Better Auth's own email service?

Better Auth's Infrastructure has a paid email service with ready made templates, on its Pro plans and above. Runearc is a general email API: the same key and domain also send your app's other mail, receive replies in inboxes and report delivery with webhooks.

Put Runearc to work

Get inboxes, sending, your own domains and MCP in one workspace. The free plan includes 3 inboxes, 3,000 emails a month and 3 custom domains, with no card.