NextSaas
NextSaas
IntroductionGetting StartedConfigurationDatabaseAuthenticationEmailsInternationalizationPaymentsStorageDeploymentChangelog

Emails

Send transactional emails using Resend.

NextSaas uses Resend for sending transactional emails. It's pre-configured to work with Better Auth's Magic Links and our custom notification system.

Setup

  1. Sign up for Resend: Create an account at Resend.
  2. Get API Key: Generate a new API key.
  3. Verify Domain: Add your domain to Resend to start sending emails.
  4. Configure Environment: Add the following to your .env file:
RESEND_API_KEY="re_123456789"
EMAIL_FROM="onboarding@resend.dev" # Or your verified domain email

Sending Emails

We provide a type-safe wrapper around the Resend SDK in src/lib/email.ts.

import { sendEmail } from "@/lib/email";

await sendEmail({
  to: "user@example.com",
  subject: "Welcome to NextSaas",
  html: "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
  text: "Welcome! Thanks for signing up.", // Optional fallback
});

Templates

Currently, we define email templates as simple HTML strings within src/lib/email.ts for simplicity and performance.

Available pre-built templates:

  • Magic Link: Sent when a user requests a magic link login.
  • Bind GitHub: Sent to paying users to link their GitHub account.
  • Repo Access Granted: Sent when GitHub repo access is successfully granted.
  • Repo Access Failed: Sent if there's an error granting access.

Customizing Templates

To customize these templates, edit the functions in src/lib/email.ts. For more complex emails, we recommend using React Email to build and export your templates.

Authentication

Secure user login with Better Auth and social providers.

Internationalization

Add multi-language support with next-intl.

On this page

SetupSending EmailsTemplatesCustomizing Templates