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
- Sign up for Resend: Create an account at Resend.
- Get API Key: Generate a new API key.
- Verify Domain: Add your domain to Resend to start sending emails.
- Configure Environment: Add the following to your
.envfile:
RESEND_API_KEY="re_123456789"
EMAIL_FROM="onboarding@resend.dev" # Or your verified domain emailSending 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.