Fix: Dunning Emails Are Now Delivered — v1.0.41
Fix: Dunning Emails Are Now Delivered — v1.0.41
Release: v1.0.41 | Category: Billing & Revenue Intelligence
What Happened
Since the dunning cron was introduced, every email step in the dunning sequence was silently doing nothing. The system logged a message and moved on:
Email skipped for reminder_day_1 on invoice abc123 — Resend not configured
Email skipped for final_warning on invoice abc123 — Resend not configured
Suspensions and cancellations were being written to the database on schedule, but customers received zero communication — no payment reminders, no warnings, and no final notices — throughout the entire dunning flow.
What the Dunning Sequence Is Supposed to Do
The dunning cron runs on a schedule and evaluates overdue invoices. For each invoice, it steps through a series of escalating actions:
| Step | Action Type | Intent |
|---|---|---|
| Day 1 | reminder_day_1 | Polite payment reminder |
| Day 2 | reminder_day_2 | Follow-up warning |
| Final | final_warning | Last notice before suspension |
| Threshold | Suspend/Cancel | DB update — account suspended or cancelled |
Prior to this fix, only the last column (DB updates) was functioning. The entire email column was dead.
What Changed in v1.0.41
A new sendDunningEmail() helper was added to billing-crons.ts, modeled on the sendWinBackEmail() helper that already exists in churn-crons.ts. The two functions follow the same pattern: build a subject line and HTML body per action type, then dispatch via Resend using the already-registered RESEND_API_KEY.
The helper is now called inside the dunning loop for every email-based action type before any DB mutation occurs. If Resend is not reachable, the error is logged and the dunning step is not silently swallowed.
Configuration
No new environment variables are required. The fix uses the existing RESEND_API_KEY that was already registered on the platform. Ensure it is set in your environment — without it, dunning emails will still not send.
RESEND_API_KEY=re_xxxxxxxxxxxx
What You Should Expect Now
- Customers with overdue invoices will receive an email at each dunning step.
- Subject lines and HTML are scoped per action type (reminder vs. warning vs. final notice).
- Suspension and cancellation DB logic is unchanged.
- No duplicate emails — each step fires exactly once per dunning evaluation cycle.
Why This Matters
Dunning is one of the highest-leverage automated revenue recovery tools in the platform. A dunning cron that silently cancels customers without warning is worse than no dunning at all — it creates churn without giving customers a chance to recover. This fix closes that gap and activates the full intended dunning sequence.