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