iachat/app/mailers
Vishnu Narayanan c884cdefde
feat: add per-account daily rate limit for outbound emails (#13411)
Introduce a daily cap on non-channel outbound emails to prevent abuse.

Fixes https://linear.app/chatwoot/issue/CW-6418/ses-incident-jan-28

## Type of change

- [x] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality not to work as expected)

## Summary
- Adds a Redis-based daily counter to rate limit outbound emails per
account, preventing email abuse
- Covers continuity emails (WebWidget/API), conversation transcripts,
and agent notifications
  - Email channel replies are excluded (paid feature, not abusable)
- Adds account suspension check in `ConversationReplyMailer` to block
already-queued emails for suspended accounts

  ## Limit Resolution Hierarchy
1. Per-account override (`account.limits['emails']`) — SuperAdmin
configurable
2. Enterprise plan-based (`ACCOUNT_EMAILS_PLAN_LIMITS`
InstallationConfig)
3. Global default (`ACCOUNT_EMAILS_LIMIT` InstallationConfig, default:
100)
  4. Fallback (`ChatwootApp.max_limit` — effectively unlimited)

  ## Enforcement Points
  | Path | Where | Behavior |
  |------|-------|----------|
| WebWidget/API continuity |
`SendEmailNotificationService#should_send_email_notification?` |
Silently skipped |
| Widget transcript | `Widget::ConversationsController#transcript` |
Returns 429 |
| API transcript | `ConversationsController#transcript` | Returns 429 |
| Agent notifications | `Notification::EmailNotificationService#perform`
| Silently skipped |
  | Email channel replies | Not rate limited | Paid feature |
| Suspended accounts | `ConversationReplyMailer` | Blocked at mailer
level |
2026-02-03 02:06:51 +05:30
..
administrator_notifications feat: TikTok channel (#12741) 2025-12-17 07:54:50 -08:00
agent_notifications feat: sanitize inbox name (#11597) 2025-06-09 14:46:12 +05:30
team_notifications feat: Add send message, fix issues with message conditions (#4423) 2022-04-14 13:36:55 +05:30
application_mailer.rb chore: log emails sent from chatwoot (#8721) 2024-01-17 13:19:14 +04:00
conversation_reply_mailer_attachment_helper.rb fix: stream attachment handling in workers (#12870) 2025-12-05 13:02:53 -08:00
conversation_reply_mailer_helper.rb fix: stream attachment handling in workers (#12870) 2025-12-05 13:02:53 -08:00
conversation_reply_mailer.rb feat: add per-account daily rate limit for outbound emails (#13411) 2026-02-03 02:06:51 +05:30
portal_instructions_mailer.rb fix: footer in ssl_instructions email (#12076) 2025-07-31 11:44:17 -07:00
references_header_builder.rb feat: add references header to reply emails (#11719) 2025-07-29 15:54:14 +05:30