Markdown

Password reset email best practices

Password reset emails, email verification, and magic links are the highest-stakes transactional mail your product sends. A delayed or filtered message locks someone out of their own account. Send them with POST /emails (or the npm SDK) from a verified domain.

Updated Nov 30, 20263 min read

Email verification codes: how to build them so they actually arrive. Video, with captions.

This guide covers a production-ready password reset email flow: send examples, copy patterns, security habits, templates, and how to wire auth providers (Supabase, Clerk, Auth.js, Better Auth, Neon Auth).

For the deeper product architecture (tokens, latency budgets, stream isolation), see the Learn guide Password reset emails going to spam?.


  1. Create an API key in the dashboard
  2. Verify your sending domain (Domains) — prefer a transactional subdomain such as mail.yourdomain.com or tx.yourdomain.com
  3. When your app issues a reset or verify token, call Groundmail with the link in html and text
  4. Track delivery, bounce, and complaint events via webhooks

Treat provider acceptance (200 + message id) as “queued,” not “in the inbox.” Wire webhooks if support needs a delivery timeline.


Password reset email example

JavaScript
import { Groundmail } from 'groundmail'

const client = new Groundmail(process.env.GROUNDMAIL_API_KEY)

export async function sendPasswordResetEmail({
  to,
  resetUrl,
  expiresInMinutes = 30,
}: {
  to: string
  resetUrl: string
  expiresInMinutes?: number
}) {
  return client.emails.send({
    from: 'noreply@mail.yourdomain.com',
    to,
    subject: 'Reset your password',
    html: `
<p>We received a request to reset your password.</p>
<p><a href="${resetUrl}">Reset password</a></p>
<p>This link expires in ${expiresInMinutes} minutes. If you did not request a reset, you can ignore this email.</p>
`.trim(),
    text: `We received a request to reset your password.\n\nReset password: ${resetUrl}\n\nThis link expires in ${expiresInMinutes} minutes. If you did not request a reset, you can ignore this email.`,
  })
}

curl:

Terminal
curl -X POST https://api.groundmail.dev/emails \
  -H "Authorization: Bearer $GROUNDMAIL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "noreply@mail.yourdomain.com",
    "to": "user@example.com",
    "subject": "Reset your password",
    "html": "<p>We received a request to reset your password.</p><p><a href=\"https://yourapp.com/reset?token=…\">Reset password</a></p><p>This link expires in 30 minutes. If you did not request a reset, you can ignore this email.</p>",
    "text": "We received a request to reset your password.\n\nReset password: https://yourapp.com/reset?token=…\n\nThis link expires in 30 minutes. If you did not request a reset, you can ignore this email."
  }'

Copy habits that help inbox placement

  • Use a specific subject (Reset your password) — avoid vague “Action required”
  • Include a plain-text part every time
  • Put the reset URL in both the button/link and as visible text for clients that strip HTML
  • State expiry clearly
  • Never attach marketing modules or unsubscribe footers to auth mail

Email verification example

JavaScript
await client.emails.send({
  from: 'noreply@mail.yourdomain.com',
  to: user.email,
  subject: 'Verify your email',
  html: `<p>Confirm your email address:</p><p><a href="${verifyUrl}">Verify email</a></p><p>If you did not create an account, you can ignore this email.</p>`,
  text: `Confirm your email address: ${verifyUrl}\n\nIf you did not create an account, you can ignore this email.`,
})

Magic links are the same send pattern with a shorter-lived URL:

JavaScript
await client.emails.send({
  from: 'noreply@mail.yourdomain.com',
  to,
  subject: 'Your sign-in link',
  html: `<p><a href="${magicUrl}">Sign in</a></p><p>This link expires in 10 minutes.</p>`,
  text: `Sign in: ${magicUrl}\n\nThis link expires in 10 minutes.`,
})

One-time codes should stay short and readable in plain text (users often read OTP mail on a second device):

JavaScript
await client.emails.send({
  from: 'noreply@mail.yourdomain.com',
  to,
  subject: 'Your verification code',
  html: `<p>Your code is <strong>${otp}</strong>.</p><p>It expires in 10 minutes.</p>`,
  text: `Your code is ${otp}.\n\nIt expires in 10 minutes.`,
})

Security habits (application side)

Groundmail delivers the message; your app owns the token.

  • Generate high-entropy, single-use tokens and store them hashed
  • Keep expiry short (minutes for magic links / OTP; tens of minutes for password reset)
  • Return the same response whether or not the account exists (no enumeration)
  • Prefer first-party HTTPS links — avoid third-party URL shorteners in auth mail
  • Make sends idempotent so retries do not create three reset emails

Latency and deliverability

Auth mail should target seconds from user action to inbox. Budget queue time in your workers, not only the HTTP round trip to the API.

  • Authenticate the sending domain with SPF, DKIM, and DMARC before production traffic (Domains)
  • Keep auth mail on a transactional identity — do not send campaigns from the same subdomain
  • Suppress hard bounces immediately so retries do not burn reputation (Suppressions)

If resets land in spam, diagnose authentication and reputation before rewriting subject lines — see Password reset emails going to spam?.


Templates

For repeated auth copy, store HTML in Templates and send by alias with variables (reset_url, expires_in) instead of inlining markup in every service. Keep a plain-text body on the send call or in the template so filters and accessibility stay covered.


Auth providers

Supabase, Clerk, Auth.js, Better Auth and Neon Auth let you bring your own email for password resets, magic links, verification and one-time codes. Prefer a hook or callback that calls POST /emails when the provider has one. Use the SMTP relay with an SMTP credential when the product only has an SMTP form.

Provider Path Guide
Supabase Send Email hook with an Edge Function, or custom SMTP Supabase Auth email
Clerk No custom SMTP for auth templates: turn off Delivered by Clerk and deliver email.created webhooks with groundmail-clerk Clerk email
Auth.js / NextAuth The groundmail-authjs email provider Auth.js email
Better Auth sendResetPassword and sendVerificationEmail callbacks Better Auth email
Neon Auth (Managed Better Auth) Custom SMTP with an SMTP credential, or send.otp and send.magic_link webhooks that call POST /emails Neon Auth email

Whichever provider you use, send every auth message (reset, verification, magic link) from the same address on your verified domain, keep GROUNDMAIL_API_KEY in server-side env only, and include a plain-text body.


Was this page helpful?