Record why an email send was rejected or failed

Merged
SI
16d ago
+10-0

Summary

Adds a nullable reason column to email_send_log, so a rejected or failed POST /api/emails attempt records why.

Why

Most logged sends (59% in the August investigation on recoupable/app#1949) were rejected, and the log could not say why: the rejected path stored only the raw body, and the earlier error column was dropped in 20260630211500 because nothing filled it. The companion api PR writes reason as a short code then detail (recipient_not_allowed: …, invalid_body: html: …, no_account_email, auth_failed: 401, resend_error: …), so the rejection rate can be grouped by cause.

Notes

  • Additive and nullable; existing rows and writers are unaffected.
  • Merge and apply this before the api PR that writes the column.

šŸ¤– Generated with Claude Code


Summary by cubic

Adds a nullable reason column to email_send_log so rejected or failed POST /api/emails attempts can record why.

  • Most logged sends (59% in the recoupable/app#1949 investigation) were rejected with nothing to say why; the earlier error column was dropped because nothing filled it.
  • The companion api PR writes reason as a short code followed by detail, e.g. recipient_not_allowed: …, so rejection rate can be grouped by cause.
  • Additive and nullable; existing rows and writers are unaffected. Merge this before the api PR that writes the column.