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 } = await import('resend');
|
||||||
const resend = new Resend(apiKey);
|
const resend = new Resend(apiKey);
|
||||||
|
|
||||||
const hostname = process.env.NEXTAUTH_URL ? new URL(process.env.NEXTAUTH_URL).hostname : '';
|
// Use explicitly configured from address if available
|
||||||
const from = hostname && hostname !== 'localhost'
|
const configuredFrom = process.env.SMTP_FROM || process.env.RESEND_FROM || '';
|
||||||
? `Memento <noreply@${hostname}>`
|
let from: string;
|
||||||
: 'Memento <onboarding@resend.dev>';
|
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
|
// Resend supports attachments with inline content
|
||||||
const resendAttachments = attachments?.map(att => ({
|
const resendAttachments = attachments?.map(att => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user