feat(phase-9): email dispatcher — HTML templates, delivery log, test endpoint

Backend:
- app/models/email_log.py: EmailLog table (school_id, to, subject, type, status,
  error, sent_at) with EmailType + EmailStatus enums
- migrations/002_phase9_email_logs.py: Alembic migration for email_logs table
- app/templates/email/: 6 Jinja2 HTML templates — base layout, invoice,
  low_credit, license_expiry, overdue_warning, suspension
- app/services/email.py: enhanced send_email() — accepts template_name+context
  for HTML rendering, logs every attempt to email_logs, retries up to 3x on
  transient SMTP failure with exponential backoff
- app/routers/email.py: GET /api/email/logs (paginated, filterable by type/status/school),
  POST /api/email/test (send test email, super admin)
- tasks/billing.py: invoice + overdue warning + suspension emails now use HTML templates
- tasks/sms.py: low credit alert now uses HTML template
- tasks/license.py: expiry warning now uses HTML template
- app/main.py + migrations/env.py: wire in email_log model + email router

Frontend:
- EmailLogsPage.vue: table with to/subject/type badge/status badge/sent_at/error,
  type+status filters, pagination, Send Test Email modal
- router/index.ts: /email-logs route
- AppSidebar.vue: Email Logs nav item
- api.ts: getEmailLogs, sendTestEmail
This commit is contained in:
kevin-asprec
2026-03-16 14:03:02 +08:00
parent ce829a009d
commit 1febb3cfa9
22 changed files with 846 additions and 101 deletions

View File

@@ -0,0 +1,26 @@
{% extends "email/base.html" %}
{% block content %}
<h2>Overdue Invoice — Immediate Action Required</h2>
<p>Dear {{ contact_name }},</p>
<div class="alert-red">
<strong>Invoice {{ invoice_number }} is overdue. Please settle this immediately to avoid account suspension.</strong>
</div>
<div class="info-box">
<div class="row"><span class="label">Invoice Number</span><span class="value">{{ invoice_number }}</span></div>
<div class="row"><span class="label">Amount</span><span class="value">PHP {{ amount }}</span></div>
<div class="row"><span class="label">Was Due On</span><span class="value" style="color:#dc2626">{{ due_date }}</span></div>
<div class="row"><span class="label">Days Overdue</span><span class="value" style="color:#dc2626">{{ days_overdue }} days</span></div>
</div>
<p>If this invoice is not settled within <strong>{{ days_until_suspension }} days</strong>, your TapTrack
account will be automatically suspended. This will disable SMS notifications for your school.</p>
<p><a class="btn" style="background:#dc2626" href="{{ portal_url }}/portal/billing">View &amp; Settle Invoice</a></p>
<p>If you believe this is an error or need to discuss payment arrangements, please contact us
at <a href="mailto:support@taptrack.io">support@taptrack.io</a> immediately.</p>
<p>Thank you,<br><strong>TapTrack Hub Team</strong></p>
{% endblock %}