fix: Resend rejects noreply@localhost as from address

When NEXTAUTH_URL=http://localhost:3000, the hostname resolves to
'localhost' which Resend rejects. Fall back to onboarding@resend.dev
when hostname is localhost.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Sepehr Ramezani
2026-04-21 20:22:25 +02:00
parent 5b652698cc
commit 5cd828c7d7

View File

@@ -61,8 +61,9 @@ async function sendViaResend(apiKey: string, { to, subject, html, attachments }:
const { Resend } = await import('resend');
const resend = new Resend(apiKey);
const from = process.env.NEXTAUTH_URL
? `Memento <noreply@${new URL(process.env.NEXTAUTH_URL).hostname}>`
const hostname = process.env.NEXTAUTH_URL ? new URL(process.env.NEXTAUTH_URL).hostname : '';
const from = hostname && hostname !== 'localhost'
? `Memento <noreply@${hostname}>`
: 'Memento <onboarding@resend.dev>';
// Resend supports attachments with inline content