The boilerplate uses Resend as the email service provider, offering reliable transactional email delivery with excellent developer experience.
Perfect for: Transactional emails, authentication flows, notifications, and professional email delivery.
Add the required environment variables to your .env.local:
# Resend Configuration
RESEND_API_KEY="re_your_api_key_here"
EMAIL_FROM="noreply@yourdomain.com"
# For development, you can use the default
EMAIL_FROM="onboarding@resend.dev"The boilerplate provides a configured email service in src/services/email-service.ts:
// From src/services/email-service.ts
import { Resend } from 'resend'
import { env } from '@/env'
const resend = new Resend(env.RESEND_API_KEY)
export const sendEmailService = async (
payload: CreateEmailOptions,
options?: CreateEmailRequestOptions
) => {
if (env.NODE_ENV === 'development') {
payload.subject = `[DEV] ${payload.subject}`
}
const { error } = await resend.emails.send(
{
...payload,
from: env.EMAIL_FROM ?? 'onboarding@resend.dev',
},
options
)
if (error) {
console.error(error)
throw error
}
}Development Mode: In development, all email subjects are automatically prefixed with [DEV] to distinguish them from production emails.
For basic text emails, use the sendSimpleEmailService:
// From src/services/email-service.ts
export const sendSimpleEmailService = async ({
to,
subject,
text,
}: {
to: string
subject: string
text: string
}) => {
await sendEmailService({
to,
subject,
text,
from: env.EMAIL_FROM ?? 'onboarding@resend.dev',
})
}The boilerplate includes 13 specialized email functions:
// Magic link authentication
sendMagicLinkEmailService({ email, url })
// Email verification
sendVerificationEmailService({ email, url })
// Password reset
sendResetPasswordLinkEmailService({ email, url })
// OTP codes
sendOTPEmailService({ email, otp, otpLink })
// Email change verification
sendEmailChangeEmailVerificationService({ email, url })Required: Make sure these environment variables are set in your deployment environment.
# Required
RESEND_API_KEY="your-resend-api-key"
# Recommended (defaults to onboarding@resend.dev)
EMAIL_FROM="noreply@yourdomain.com"
# Used in email templates
NEXT_PUBLIC_APP_URL="https://yourdomain.com"The email service includes built-in error handling:
// From src/services/email-service.ts
const { error } = await resend.emails.send(emailData)
if (error) {
console.error(error)
throw error
}Errors are logged and thrown, allowing the calling code to handle them appropriately.
[DEV]EMAIL_FROM to use your verified domainResend configured! Your application can now send professional transactional emails with reliable delivery and excellent analytics.