Skip to content

[Backend] Add email notification service for course and credential events #121

Description

@jobbykings

Description

Users currently receive no email notifications for key platform events. We need an email service that sends transactional emails for course enrollment confirmations, credential issuance, payment receipts, assignment feedback, and account security alerts.

Definition of Done

  • Email service abstraction with pluggable provider (starting with SendGrid or AWS SES)
  • HTML email templates for: enrollment confirmation, credential issued, payment receipt, assignment graded, password changed, new login alert
  • Templates use responsive HTML with plain-text fallback
  • Email sending is async/non-blocking: queued via the existing transaction queue
  • Retry with exponential backoff (3 attempts max) on send failure
  • Email preference management: users can opt out of specific email types in Settings
  • Rate limiting: max X emails per user per hour to prevent spam
  • Email events tracked (sent, delivered, opened, bounced) for analytics
  • Admin can trigger manual resend of specific email types

Files to Modify

  • NEW: backend/src/services/emailService.ts
  • NEW: backend/src/services/emailTemplates.ts
  • NEW: backend/src/services/__tests__/emailService.test.ts
  • NEW: backend/src/templates/emails/ (directory for HTML templates)
  • backend/src/services/notificationService.ts (add email channel)
  • backend/src/controllers/userController.ts (trigger emails on events)
  • backend/src/controllers/EnrollmentController.ts
  • backend/src/controllers/PaymentController.ts
  • backend/src/controllers/assignmentController.ts
  • backend/src/models/User.ts (add email preferences field)
  • backend/SETUP_GUIDE.md (add EMAIL_PROVIDER, SENDGRID_API_KEY, EMAIL_FROM to env var documentation)

Acceptance Criteria

  • Enrolling in a course sends a styled confirmation email within 30 seconds
  • Credential issuance sends email with credential ID and verification link
  • Payment confirmation email includes transaction hash and amount
  • Email includes plain-text version alongside HTML
  • User opts out of "Assignment Graded" emails; they stop receiving them but still get security alerts
  • Email sending failure retries 3 times with exponential backoff
  • No more than 10 emails sent to a single user per hour regardless of events
  • Admin can view email send history and manually retry failed sends

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions