fix: pass full config to sendViaResend, force-recreate container after env update
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 39s

Made-with: Cursor
This commit is contained in:
2026-04-25 22:48:05 +02:00
parent 266551e82b
commit 99ac686ac0
2 changed files with 8 additions and 8 deletions

View File

@@ -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

View File

@@ -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<MailResult> {
async function sendViaResend(apiKey: string, config: Record<string, string>, { to, subject, html, attachments }: MailOptions): Promise<MailResult> {
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 <noreply@${hostname}>`