Email Construction Guide

Version: 2.0.0 | Last Updated: January 2026 | Status: Production

1. Overview

JGPNR uses a queue-based email system powered by BullMQ for reliable, asynchronous email delivery. All transactional emails are HTML-formatted with inline styles for maximum email client compatibility.

Email System Components

Component Location Purpose
Email Service src/modules/email/email.service.ts Core email logic
Email Queue src/config/queue.ts BullMQ queue configuration
Email Templates src/modules/email/templates/ HTML template files

2. Email Architecture

Queue-Based Delivery

Trigger
Order/Payment
Email Service
Build Template
BullMQ
Job Queue
Worker
Process Job
SMTP
Delivered

3. Email Templates

1. Order Confirmation Email

File: templates/orderResult.ts
Trigger: Order created successfully.

Dynamic Data

Placeholder Source Description
${customerName} order.customer.firstName + lastName Full customer name
${orderNumber} order.orderNumber Order ID (e.g., ORD-123456)
${ticketCode} ticket.ticketCode Ticket ID (e.g., TKT-ABC123)
${validUntil} ticket.validUntil (formatted) Ticket expiry date
${gameArenaLocation} systemSettings.gameArenaLocation Physical venue address

Email Types & Triggers

All transactional emails are sent through the BullMQ queue with retry logic.

Email Type Trigger Template File Attachments
Order Confirmation Order created (PENDING) orderConfirmation.template.ts None
Payment Confirmation Payment verified (PAID) paymentConfirmation.template.ts QR Code images
Session Reminder (24h) 20-28 hours before session reminder.template.ts None
Session Reminder (2h) 1-3 hours before session reminder.template.ts None
Expiry Reminder 1d, 3d (7d for subs) before expiry expiryReminder.template.ts None
Shipment Update Status → SHIPPED or DELIVERED shipmentUpdate.template.ts None
Admin Campaign Manual send from admin panel campaign.template.ts Optional
Admin Reports Scheduled (daily/weekly/monthly) scheduler.jobs.ts (inline) CSV exports (monthly)

Expiry Date Calculation

Note: The expiry date shown in emails is calculated dynamically using ticketLifecycle.utils.ts.

Reminder Timing Configuration

Setting Field Default Description
24h Window Min reminder24HoursMin 20 hours Lower bound for 24h reminder
24h Window Max reminder24HoursMax 28 hours Upper bound for 24h reminder
2h Window Min reminder2HoursMin 1 hour Lower bound for 2h reminder
2h Window Max reminder2HoursMax 3 hours Upper bound for 2h reminder

Error Handling

4. Dynamic Data & Placeholders

Two types of placeholders are used:

System Settings Placeholders

Placeholder Source
{{businessName}} SystemSettings.businessName
{{businessAddress}} SystemSettings.businessAddress
{{supportEmail}} SystemSettings.supportEmail
{{contactPhone}} SystemSettings.contactPhone

Runtime Placeholders

Placeholder Source
${customerName} order.customer.firstName
${orderNumber} order.orderNumber
${ticketCode} ticket.ticketCode
${validUntil} ticket.validUntil (formatted)
${totalAmount} order.totalAmount (formatted)

5. Reminder Logic

Cron jobs run hourly to check for:

Session Reminders

Expiry Reminders

Note: Reminder intervals are configurable via SystemSettings in the admin panel.

6. Attachments

PDF Generation

QR Code Attachments

7. Styling Guidelines

Emails must be compatible with Outlook, Gmail, and Apple Mail.

8. Branding Configuration

9. Error Handling

Failed jobs are automatically retried 3 times by BullMQ. If SMTP fails, the job remains in the failed queue for inspection.

Monitoring