From 99ac686ac0a1b90797c3370d1ff3e73744a6df02 Mon Sep 17 00:00:00 2001 From: sepehr Date: Sat, 25 Apr 2026 22:48:05 +0200 Subject: [PATCH] fix: pass full config to sendViaResend, force-recreate container after env update Made-with: Cursor --- .gitea/workflows/deploy.yaml | 2 ++ memento-note/lib/mail.ts | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 513801c..90690a8 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -111,6 +111,8 @@ jobs: upsert JINA_API_KEY "$JINA_API_KEY" echo ".env.docker updated" + # Redémarre les containers pour appliquer les nouvelles vars d'env + cd /opt/memento && docker compose up -d --force-recreate memento-note ENDSSH - name: Deploy via SSH diff --git a/memento-note/lib/mail.ts b/memento-note/lib/mail.ts index 8f35223..ed0ccff 100644 --- a/memento-note/lib/mail.ts +++ b/memento-note/lib/mail.ts @@ -41,12 +41,12 @@ export async function sendEmail({ to, subject, html, attachments }: MailOptions, // Force Resend (no fallback) if (provider === 'resend') { if (!resendKey) return { success: false, error: 'No Resend API key configured' }; - return sendViaResend(resendKey, { to, subject, html, attachments }); + return sendViaResend(resendKey, config, { to, subject, html, attachments }); } // Auto: try Resend, fall back to SMTP if (resendKey) { - const result = await sendViaResend(resendKey, { to, subject, html, attachments }); + const result = await sendViaResend(resendKey, config, { to, subject, html, attachments }); if (result.success) return result; console.warn('[Mail] Resend failed, falling back to SMTP:', result.error); @@ -56,22 +56,20 @@ export async function sendEmail({ to, subject, html, attachments }: MailOptions, return sendViaSMTP(config, { to, subject, html, attachments }); } -async function sendViaResend(apiKey: string, { to, subject, html, attachments }: MailOptions): Promise { +async function sendViaResend(apiKey: string, config: Record, { to, subject, html, attachments }: MailOptions): Promise { try { const { Resend } = await import('resend'); const resend = new Resend(apiKey); - // Use explicitly configured from address if available - const configuredFrom = process.env.SMTP_FROM || process.env.RESEND_FROM || ''; + // Use configured from address (DB config takes priority over env vars) + const configuredFrom = config.SMTP_FROM || process.env.SMTP_FROM || config.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 || ''; + const rawUrl = config.NEXTAUTH_URL || 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 `