fix(email): adiciona tratamento de erros no envio de e-mails de automacao
Some checks failed
Some checks failed
- 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:
parent
8a237a820d
commit
158fb32b8a
1 changed files with 19 additions and 2 deletions
|
|
@ -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 }
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue