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 => ({