fix(email): adiciona tratamento de erros no envio de e-mails de automacao
Some checks failed
CI/CD Web + Desktop / Detect changes (push) Successful in 5s
Quality Checks / Lint, Test and Build (push) Successful in 3m55s
CI/CD Web + Desktop / Deploy (VPS Linux) (push) Successful in 3m58s
CI/CD Web + Desktop / Deploy Convex functions (push) Failing after 1m22s

- 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 <noreply@anthropic.com>
This commit is contained in:
rever-tecnologia 2025-12-17 19:05:24 -03:00
parent 8a237a820d
commit 158fb32b8a

View file

@ -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 }
},
})