Email
Resend
Setting up Resend as your email provider.
Setup
- Create an account at resend.com
- Add and verify your domain in the Resend dashboard
- Create an API key
- Set environment variables:
NEXT_PUBLIC_EMAIL_SERVICE="resend"
NEXT_RESEND_API_KEY="re_..."
NEXT_RESEND_FROM_EMAIL="noreply@yourdomain.com"Testing
During development, Resend allows sending emails only from onboarding@resend.dev. Set:
NEXT_RESEND_FROM_EMAIL="onboarding@resend.dev"Switch to your verified domain email before going to production.
How it works
The Resend provider in lib/services/email-service.ts:
function createResendProvider(): EmailProvider {
const fromEmail = process.env.NEXT_RESEND_FROM_EMAIL || "onboarding@resend.dev";
return {
async send({ to, subject, html, text, replyTo }) {
const { Resend } = await import("resend");
const resend = new Resend(process.env.NEXT_RESEND_API_KEY);
const { data, error } = await resend.emails.send({
from: `${APP_NAME} <${fromEmail}>`,
to: [to],
subject,
html,
text,
...(replyTo && { replyTo: [replyTo] }),
});
if (error) throw new Error(error.message);
return { success: true, messageId: data?.id };
},
};
}The Resend SDK is dynamically imported so it doesn't add to the bundle when Mailgun is used instead.