Markdown

Better Auth email with Groundmail

Better Auth has a large plugin catalog (Magic Link, Email OTP, Organization, Stripe, etc.).

Updated Nov 30, 20262 min read

What it does not have is a third-party “email provider” plugin. Email delivery is always your callback:

Surface Callback you supply
Core email verification emailVerification.sendVerificationEmail
Core password reset emailAndPassword.sendResetPassword
Magic Link plugin magicLink({ sendMagicLink })
Email OTP plugin emailOTP({ sendVerificationOTP })
Organization invites organization({ sendInvitationEmail })

Groundmail’s integration is createBetterAuthEmail from groundmail-better-auth: one helper that returns those callbacks, wired to POST /emails.

Better Auth’s own hosted mail (@better-auth/infra) is a separate product. This guide is for bringing your Groundmail account.

Using Neon Auth? Neon runs Better Auth for you (Managed Better Auth), so there's no betterAuth() config to pass these callbacks to. Use custom SMTP or Neon's send.otp and send.magic_link webhooks instead: see Neon Auth email.


Prerequisites

  1. Groundmail account + gm_… API key
  2. Verified sending domain (or Sandbox for self-tests — see Quickstart)
  3. Better Auth app
Terminal
npm install groundmail-better-auth groundmail better-auth
Terminal
GROUNDMAIL_API_KEY=gm_your_key_here

Public package: groundmail-better-auth (also available as groundmail/better-auth from the core SDK).


Full setup (core + plugins)

TypeScript
// lib/auth.ts
import { betterAuth } from 'better-auth'
import { magicLink, emailOTP, organization } from 'better-auth/plugins'
import { createBetterAuthEmail } from 'groundmail-better-auth'

const email = createBetterAuthEmail({
  from: 'noreply@yourdomain.com',
  apiKey: process.env.GROUNDMAIL_API_KEY!,
  appUrl: process.env.BETTER_AUTH_URL, // used for invite links
})

export const auth = betterAuth({
  emailVerification: {
    sendVerificationEmail: email.sendVerificationEmail,
  },
  emailAndPassword: {
    enabled: true,
    sendResetPassword: email.sendResetPassword,
  },
  plugins: [
    magicLink({
      sendMagicLink: email.sendMagicLink,
    }),
    emailOTP({
      sendVerificationOTP: email.sendVerificationOTP,
    }),
    organization({
      sendInvitationEmail: email.sendInvitationEmail,
    }),
  ],
})

Only enable the plugins you use. Core callbacks work without any plugins.


What each callback sends

Helper Tag Content
sendVerificationEmail auth=verify Verification link
sendResetPassword auth=reset Reset link
sendMagicLink auth=magic-link Sign-in link
sendVerificationOTP auth=otp-{type} One-time code (sign-in, email-verification, forget-password)
sendInvitationEmail auth=invite Org invite link ({appUrl}/accept-invitation/{id})

Customize templates with email.sendAuthEmail({ to, subject, html, text, tag }) or email.sendLinkEmail(...).


Options

Option Default Purpose
from required Verified sender
apiKey process.env.GROUNDMAIL_API_KEY API key
baseUrl https://api.groundmail.dev API base URL
appUrl — Base URL for organization invite links
fireAndForget true Don’t await send in the auth request (Better Auth timing guidance). Set false in tests.
client — Inject a Groundmail instance

Was this page helpful?