Skip to content

feat: add branded email templates with local preview (#606)#963

Open
snehxa27 wants to merge 1 commit into
imDarshanGK:mainfrom
snehxa27:feat/email-templates-606
Open

feat: add branded email templates with local preview (#606)#963
snehxa27 wants to merge 1 commit into
imDarshanGK:mainfrom
snehxa27:feat/email-templates-606

Conversation

@snehxa27
Copy link
Copy Markdown

@snehxa27 snehxa27 commented Jun 8, 2026

Summary

This PR resolves #606 by replacing plain-text and inline HTML emails with reusable, branded transactional templates. All emails share a consistent QyverixAI visual identity (purple header, dark content area, light footer) and are rendered through a single Jinja2 + premailer pipeline in email_service.py.

What changed:

  • Added 5 HTML templates under backend/app/templates/email/base.html, welcome.html, reset.html, notification.html, and digest.html
  • Refactored email_service.py to use render_template() with premailer CSS inlining for Gmail/Outlook compatibility
  • Added dev-only preview routes so contributors can iterate on designs without sending real emails
  • Wired welcome email delivery on signup (background task, skipped gracefully when SMTP is not configured)
  • Enhanced digest emails with 4-week score trends, text sparklines, focus recommendations, streak callouts, and feedback links
  • Added 35 tests covering template rendering, accessibility basics, preview routes, and SMTP message construction

Motivation

Transactional emails previously lacked branding and consistent styling. This made system notifications harder to recognize and reduced perceived product quality. A template-based approach with a local preview mechanism lets contributors design and review emails quickly while keeping production sends email-client safe.

Implementation details

Templates

All templates extend base.html, which provides:

  • Shared header, footer, and responsive styles
  • Hidden preheader text for inbox previews
  • Footer links: Privacy Policy, Terms, Notification Preferences
  • Table-based layout with inline CSS (via premailer at send time)
Template Purpose Highlights
welcome.html Sent after signup 3-step onboarding, "What to expect" section
reset.html Password reset Security context (time, IP, location), expiry warning
notification.html Analysis complete / alerts 3 metric cards, primary + secondary CTAs
digest.html Weekly digest Score sparkline, focus recommendations, streak callout, feedback links

email_service.py

  • render_template(name, context) — Jinja2 render + optional premailer inlining
  • send_welcome_email(), send_password_reset_email(), send_notification_email(), send_digest()
  • compute_subscriber_stats() extended with weekly score history, sparklines, and recommendations
  • Plain-text fallbacks retained for all email types

Preview routes (development only)

Disabled when ENVIRONMENT=production.

Route Description
GET /email-preview Index listing all available templates
GET /email-preview/{template} Render template with sample data
GET /dev/email-preview/{template} Same preview under /dev prefix

Common URL typos (e.g. welcom) redirect to the correct template.

Screenshot 2026-06-08 at 8 20 14 PM Screenshot 2026-06-08 at 8 20 07 PM Screenshot 2026-06-08 at 8 20 34 PM Screenshot 2026-06-08 at 8 20 26 PM

Other changes

  • auth.py — sends welcome email in background after successful signup
  • config.py — adds ENVIRONMENT setting and is_production helper
  • requirements.txt — adds jinja2 and premailer
  • .env.example — documents ENVIRONMENT=development

How to test

cd backend
pip install -r requirements.txt
pytest tests/test_email_templates.py tests/test_digest.py -v
uvicorn app.main:app --reload

Introduce reusable Jinja2 transactional email templates with premailer
CSS inlining, dev preview routes, welcome email on signup, and tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
@snehxa27 snehxa27 requested a review from imDarshanGK as a code owner June 8, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add email templates for notifications with branding

1 participant