From ea57c022fb9f016891040b0b584ba44edc11cdf1 Mon Sep 17 00:00:00 2001 From: sepehr Date: Sat, 25 Apr 2026 22:22:24 +0200 Subject: [PATCH] fix: Resend from address - reject IP/localhost, use SMTP_FROM if set Made-with: Cursor --- memento-note/lib/mail.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/memento-note/lib/mail.ts b/memento-note/lib/mail.ts index 3ab6222..1b10a71 100644 --- a/memento-note/lib/mail.ts +++ b/memento-note/lib/mail.ts @@ -61,10 +61,22 @@ async function sendViaResend(apiKey: string, { to, subject, html, attachments }: const { Resend } = await import('resend'); const resend = new Resend(apiKey); - const hostname = process.env.NEXTAUTH_URL ? new URL(process.env.NEXTAUTH_URL).hostname : ''; - const from = hostname && hostname !== 'localhost' - ? `Memento ` - : 'Memento '; + // Use explicitly configured from address if available + const configuredFrom = process.env.SMTP_FROM || process.env.RESEND_FROM || ''; + let from: string; + if (configuredFrom) { + // Wrap in display name if it's a plain email + from = configuredFrom.includes('<') ? configuredFrom : `Memento <${configuredFrom}>`; + } else { + const rawUrl = process.env.NEXTAUTH_URL || ''; + let hostname = ''; + try { hostname = rawUrl ? new URL(rawUrl).hostname : ''; } catch {} + // IP addresses and localhost are not valid email domains for Resend + const isIP = /^[\d.]+$/.test(hostname); + from = hostname && hostname !== 'localhost' && !isIP + ? `Memento ` + : 'Memento '; + } // Resend supports attachments with inline content const resendAttachments = attachments?.map(att => ({