Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.refactkit.com/llms.txt

Use this file to discover all available pages before exploring further.

RefactKit sends transactional emails — team invitations, password resets, and email verification links — through Resend, a developer-first email platform. Better Auth handles the trigger points automatically: whenever an invitation is created or a user requests a password reset, it calls the sendEmail utility without any extra wiring on your part. Your job is to configure Resend and set the right environment variables.

How email sending works

RefactKit uses the Resend REST API to send emails. The sendEmail utility reads your API key from the RESEND_API_KEY environment variable and the sender address from EMAIL_FROM, then calls the Resend /emails endpoint:
export async function sendEmail({
  to,
  subject,
  html,
}: {
  to: string
  subject: string
  html: string
}) {
  const response = await fetch('https://api.resend.com/emails', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.RESEND_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      from: process.env.EMAIL_FROM,
      to,
      subject,
      html,
    }),
  })
  // ...
}
Better Auth calls this function automatically when a member invitation is sent, when a new user verifies their email, and when a user requests a password reset.

Emails sent automatically

TriggerEmail type
User invites a team memberOrganization invitation
User requests a password resetPassword reset link
New user registersEmail verification link
You do not need to call sendEmail directly for these flows — Better Auth handles all three.

Configure Resend

1

Create a Resend account

Go to resend.com and sign up for a free account.
2

Verify your sending domain

In the Resend dashboard, navigate to Domains and add your domain. Resend will give you DNS records (TXT and MX) to add through your DNS provider. Wait for verification to complete — this typically takes a few minutes to a few hours depending on your DNS TTL.
During development you can send from Resend’s shared onboarding@resend.dev address without domain verification. This is not suitable for production because emails will show as coming from Resend’s domain, not yours.
3

Generate an API key

Navigate to API Keys in the Resend dashboard and create a new key with Sending access. Copy the key — it starts with re_.
4

Set environment variables

Add the following to your .env file:
RESEND_API_KEY="re_your_resend_api_key_here"
EMAIL_FROM="Your App Name <noreply@yourdomain.com>"
RESEND_API_KEY authenticates requests to Resend’s API. EMAIL_FROM sets the sender name and address that appears in every outgoing email. The domain in this address must be verified in Resend.

Environment variables reference

VariableRequiredDescription
RESEND_API_KEYYesYour Resend API key (re_...)
EMAIL_FROMYesSender address shown to recipients
Never commit .env to version control. For production deployments, set these variables in your hosting platform’s environment configuration (e.g., Vercel’s Environment Variables dashboard).

Call sendEmail directly

If you need to send a custom email outside of the auth flows — for example, a welcome email after onboarding or a notification when a new gallery image is uploaded — call sendEmail from a server function:
import { createServerFn } from '@tanstack/react-start'
import { sendEmail } from '@/lib/email'

export const sendWelcomeEmail = createServerFn({ method: 'POST' })
  .handler(async ({ data }: { data: { to: string; orgName: string } }) => {
    await sendEmail({
      to: data.to,
      subject: `Welcome to ${data.orgName}`,
      html: `<p>You've been added to <strong>${data.orgName}</strong>. Log in to get started.</p>`,
    })
  })
sendEmail only runs on the server — RESEND_API_KEY is not exposed to the browser — so always call it from a createServerFn handler or another server-only module.

Test email delivery locally

Resend provides a test mode for local development. Use your Resend API key in .env and send to any address — Resend will deliver the email through their sandbox without hitting your sending limits. Check the Emails section of your Resend dashboard to inspect sent emails and their delivery status.