From 158fb32b8a3015de90317dfdc0e27c95bf3ee621 Mon Sep 17 00:00:00 2001 From: rever-tecnologia Date: Wed, 17 Dec 2025 19:05:24 -0300 Subject: [PATCH] fix(email): adiciona tratamento de erros no envio de e-mails de automacao MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Adiciona try-catch para cada envio individual - Registra logs detalhados de sucesso e falha por destinatario - Retorna informacao sobre quantos e-mails falharam - Imprime resumo de envios no console para debug 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- convex/ticketNotifications.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/convex/ticketNotifications.ts b/convex/ticketNotifications.ts index 5b234fd..50f2246 100644 --- a/convex/ticketNotifications.ts +++ b/convex/ticketNotifications.ts @@ -535,10 +535,27 @@ export const sendAutomationEmail = action({ ctaUrl: emailProps.ctaUrl, }) + const results: Array<{ recipient: string; sent: boolean; error?: string }> = [] + for (const recipient of recipients) { - await sendSmtpMail(smtp, recipient, subject, html) + try { + await sendSmtpMail(smtp, recipient, subject, html) + results.push({ recipient, sent: true }) + console.log(`[automation-email] Enviado para ${recipient}`) + } catch (error) { + const errorMessage = error instanceof Error ? error.message : String(error) + results.push({ recipient, sent: false, error: errorMessage }) + console.error(`[automation-email] Falha ao enviar para ${recipient}: ${errorMessage}`) + } } - return { ok: true, sent: recipients.length } + const sent = results.filter((r) => r.sent).length + const failed = results.filter((r) => !r.sent).length + + if (failed > 0) { + console.error(`[automation-email] Resumo: ${sent}/${recipients.length} enviados, ${failed} falhas`) + } + + return { ok: sent > 0, sent, failed, results } }, })