fix: Resend from address - reject IP/localhost, use SMTP_FROM if set
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 38s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 38s
Made-with: Cursor
This commit is contained in:
@@ -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 <noreply@${hostname}>`
|
||||
: 'Memento <onboarding@resend.dev>';
|
||||
// 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 <noreply@${hostname}>`
|
||||
: 'Memento <onboarding@resend.dev>';
|
||||
}
|
||||
|
||||
// Resend supports attachments with inline content
|
||||
const resendAttachments = attachments?.map(att => ({
|
||||
|
||||
Reference in New Issue
Block a user