# Email Templates - Complete Mapping Guide

## 📧 Template Overview

All email templates have been designed to be **dynamic** and **consistent**. Each template includes:
- ✅ Only ONE action button: **"View Request Details"** (redirects to `/request/[RequestNumber]`)
- ✅ Fully responsive design (mobile-friendly)
- ✅ Professional Royal Enfield branding
- ✅ Dynamic placeholders for personalization
- ✅ Consistent footer with disclaimer

---

## 📋 Template Inventory (10 Templates)

### 1. **RequestCreated.html**
**Trigger:** When a new workflow request is created  
**Recipients:** Initiator  
**Purpose:** Confirm request submission and inform about next steps  

**Placeholders:**
- `[InitiatorName]` - Name of the person who created the request
- `[FirstApproverName]` - Name of the first approver
- `[RequestId]` - Request number (e.g., REQ-2025-12-0013)
- `[RequestTitle]` - Title of the request
- `[RequestType]` - Type of request
- `[Priority]` - Priority level (LOW, MEDIUM, HIGH, CRITICAL)
- `[RequestDate]` - Creation date
- `[RequestTime]` - Creation time
- `[TotalApprovers]` - Total number of approvers
- `[ExpectedTAT]` - Expected turnaround time in hours
- `[ViewDetailsLink]` - Link to request (baseURL/request/requestNumber)
- `[CompanyName]` - Company name (e.g., Royal Enfield)

**Priority:** High (send immediately after request creation)

---

### 2. **ApprovalRequest.html**
**Trigger:** When a request is assigned to an approver (single approver)  
**Recipients:** Approver  
**Purpose:** Notify approver about pending approval request  

**Placeholders:**
- `[ApproverName]` - Name of the approver
- `[InitiatorName]` - Name of the initiator
- `[RequestId]` - Request number
- `[RequestDate]` - Submission date
- `[RequestTime]` - Submission time
- `[RequestType]` - Type of request
- `[RequestDescription]` - Brief description
- `[PrioritySection]` - Dynamic section (show only if priority is HIGH/CRITICAL)
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Dynamic Sections:**
- `[PrioritySection]`: Show alert box if priority is HIGH or CRITICAL

**Priority:** High (send immediately when assigned)

---

### 3. **MultiApproverRequest.html**
**Trigger:** When a request is assigned to an approver (multi-level workflow)  
**Recipients:** Approver in multi-level workflow  
**Purpose:** Notify approver with approval chain visibility  

**Placeholders:**
- `[ApproverName]` - Name of the approver
- `[InitiatorName]` - Name of the initiator
- `[RequestId]` - Request number
- `[RequestDate]` - Submission date
- `[RequestTime]` - Submission time
- `[RequestType]` - Type of request
- `[ApproverLevel]` - Current approver's level (e.g., 2)
- `[TotalApprovers]` - Total approvers (e.g., 5)
- `[ApproversList]` - Dynamic HTML showing approval chain with status
- `[RequestDescription]` - Brief description
- `[PrioritySection]` - Dynamic section for high priority
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Dynamic Sections:**
- `[ApproversList]`: Generate HTML for each approver with status (✓ Approved, numbered for current, grayed for pending)
- `[PrioritySection]`: Show if HIGH/CRITICAL priority

**Priority:** High (send immediately when assigned)

---

### 4. **ApprovalConfirmation.html**
**Trigger:** When an approver approves a request  
**Recipients:** Initiator (and optionally other stakeholders)  
**Purpose:** Confirm approval action  

**Placeholders:**
- `[InitiatorName]` - Name of the initiator
- `[ApproverName]` - Name of the approver who approved
- `[RequestId]` - Request number
- `[ApprovalDate]` - Approval date
- `[ApprovalTime]` - Approval time
- `[RequestType]` - Type of request
- `[ApproverComments]` - Comments from approver
- `[StatusSection]` - Dynamic section for workflow status
- `[NextStepsSection]` - Dynamic section for next steps
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Dynamic Sections:**
- `[StatusSection]`: Show if more approvals are pending
- `[NextStepsSection]`: Show what happens next (if final approval, show closure instructions)

**Priority:** High (send immediately after approval)

---

### 5. **RejectionNotification.html**
**Trigger:** When an approver rejects a request  
**Recipients:** Initiator (and optionally other stakeholders)  
**Purpose:** Notify about rejection  

**Placeholders:**
- `[InitiatorName]` - Name of the initiator
- `[ApproverName]` - Name of the approver who rejected
- `[RequestId]` - Request number
- `[RejectionDate]` - Rejection date
- `[RejectionTime]` - Rejection time
- `[RequestType]` - Type of request
- `[RejectionReason]` - Reason for rejection
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Priority:** Critical (send immediately after rejection)

---

### 6. **TATReminder.html**
**Trigger:** When TAT deadline is approaching (e.g., 80% of TAT elapsed)  
**Recipients:** Approver  
**Purpose:** Remind approver about pending action  

**Placeholders:**
- `[ApproverName]` - Name of the approver
- `[RequestId]` - Request number
- `[RequestTitle]` - Title of the request
- `[InitiatorName]` - Name of the initiator
- `[AssignedDate]` - Date when assigned to approver
- `[TATDeadline]` - TAT deadline date and time
- `[TimeRemaining]` - Time remaining (e.g., "4 hours")
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Priority:** High (send based on TAT threshold - e.g., when 80% elapsed)

---

### 7. **TATBreached.html**
**Trigger:** When TAT deadline has passed  
**Recipients:** Approver, Management (optionally)  
**Purpose:** Escalate breached TAT  

**Placeholders:**
- `[ApproverName]` - Name of the approver
- `[RequestId]` - Request number
- `[RequestTitle]` - Title of the request
- `[InitiatorName]` - Name of the initiator
- `[Priority]` - Priority level
- `[AssignedDate]` - Date when assigned
- `[TATDeadline]` - Original TAT deadline
- `[TimeOverdue]` - Time overdue (e.g., "6 hours overdue")
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Priority:** Critical (send immediately when TAT breached)

---

### 8. **WorkflowPaused.html**
**Trigger:** When a workflow is paused  
**Recipients:** Initiator, Current Approver, Spectators  
**Purpose:** Inform about workflow pause  

**Placeholders:**
- `[RecipientName]` - Name of the recipient
- `[RequestId]` - Request number
- `[RequestTitle]` - Title of the request
- `[PausedByName]` - Name of person who paused
- `[PausedDate]` - Pause date
- `[PausedTime]` - Pause time
- `[ResumeDate]` - Scheduled resume date
- `[PauseReason]` - Reason for pause
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Priority:** Medium (send when workflow is paused)

---

### 9. **WorkflowResumed.html**
**Trigger:** When a workflow is resumed (auto or manual)  
**Recipients:** Initiator, Current Approver, Spectators  
**Purpose:** Inform about workflow resumption  

**Placeholders:**
- `[RecipientName]` - Name of the recipient
- `[RequestId]` - Request number
- `[RequestTitle]` - Title of the request
- `[ResumedByText]` - Text explaining resume (e.g., "automatically" or "by John Doe")
- `[ResumedDate]` - Resume date
- `[ResumedTime]` - Resume time
- `[PausedDuration]` - Duration of pause (e.g., "3 days")
- `[CurrentApprover]` - Name of current approver
- `[NewTATDeadline]` - Updated TAT deadline
- `[ActionRequiredSection]` - Dynamic section for approvers only
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Dynamic Sections:**
- `[ActionRequiredSection]`: Show only to the current approver

**Priority:** High (send immediately when resumed)

---

### 10. **ParticipantAdded.html**
**Trigger:** When someone is added as Approver/Spectator to existing request  
**Recipients:** Newly added participant  
**Purpose:** Welcome participant and explain their role  

**Placeholders:**
- `[ParticipantName]` - Name of the participant
- `[ParticipantRole]` - Role (Approver, Spectator)
- `[AddedByName]` - Name of person who added them
- `[RoleDescription]` - Description of role
- `[RequestId]` - Request number
- `[RequestTitle]` - Title of the request
- `[InitiatorName]` - Name of the initiator
- `[RequestType]` - Type of request
- `[CurrentStatus]` - Current workflow status
- `[AddedDate]` - Date added
- `[AddedTime]` - Time added
- `[RequestDescription]` - Brief description
- `[PermissionsContent]` - Dynamic HTML explaining permissions
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Dynamic Sections:**
- `[PermissionsContent]`: Different content for Approver vs Spectator

**Priority:** Medium (send when participant is added)

---

## 🆕 Additional Templates

### 11. **ApproverSkipped.html**
**Trigger:** When an approver is skipped in the workflow  
**Recipients:** Skipped approver, Initiator, other stakeholders  
**Purpose:** Notify about level skip  

**Placeholders:**
- `[RecipientName]` - Name of the recipient
- `[RequestId]` - Request number
- `[RequestTitle]` - Title of the request
- `[SkippedApproverName]` - Name of skipped approver
- `[SkippedByName]` - Name of person who skipped
- `[SkippedDate]` - Skip date
- `[SkippedTime]` - Skip time
- `[NextApproverName]` - Next approver in line
- `[SkipReason]` - Reason for skipping
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Priority:** Medium (send when approver is skipped)

---

### 12. **RequestClosed.html**
**Trigger:** When initiator closes the request after all approvals  
**Recipients:** All participants (approvers, spectators)  
**Purpose:** Notify about request closure and provide summary  

**Placeholders:**
- `[RecipientName]` - Name of the recipient
- `[RequestId]` - Request number
- `[RequestTitle]` - Title of the request
- `[InitiatorName]` - Name of the initiator
- `[CreatedDate]` - Request creation date
- `[ClosedDate]` - Closure date
- `[ClosedTime]` - Closure time
- `[TotalDuration]` - Total duration from creation to closure
- `[ConclusionSection]` - Dynamic section for conclusion remarks
- `[TotalApprovers]` - Total number of approvers
- `[TotalApprovals]` - Total approvals received
- `[WorkNotesCount]` - Number of work notes
- `[DocumentsCount]` - Number of documents
- `[ViewDetailsLink]` - Link to request
- `[CompanyName]` - Company name

**Dynamic Sections:**
- `[ConclusionSection]`: Show if conclusion remarks provided

**Priority:** Low (send when request is closed)

---

## 🔄 Dynamic Placeholder Format

### Standard Placeholders
Format: `[PlaceholderName]`
Example: `[InitiatorName]` → Replace with actual name

### Dynamic Sections
Format: `[SectionName]`
These should be replaced with HTML blocks or empty strings based on conditions.

**Example for Priority Section:**
```html
<!-- If Priority is HIGH or CRITICAL, replace [PrioritySection] with: -->
<div style="padding: 20px; background-color: #fff3cd; border-left: 4px solid #ffc107; border-radius: 4px; margin-bottom: 30px;">
    <h3 style="margin: 0 0 10px; color: #856404; font-size: 16px; font-weight: 600;">High Priority</h3>
    <p style="margin: 0; color: #856404; font-size: 14px; line-height: 1.6;">
        This request has been marked as HIGH priority and requires prompt attention.
    </p>
</div>

<!-- Otherwise, replace [PrioritySection] with empty string -->
```

---

## 🎯 Priority-Based Sending Strategy

### Critical Priority (Send Immediately)
- TATBreached.html
- RejectionNotification.html

### High Priority (Send within 1 minute)
- RequestCreated.html
- ApprovalRequest.html
- MultiApproverRequest.html
- ApprovalConfirmation.html
- TATReminder.html
- WorkflowResumed.html

### Medium Priority (Send within 5 minutes)
- WorkflowPaused.html
- ParticipantAdded.html
- ApproverSkipped.html

### Low Priority (Can be batched)
- RequestClosed.html

---

## 🛠️ Implementation Notes

### Base URL Configuration
All `[ViewDetailsLink]` placeholders should be replaced with:
```
{baseURL}/request/{requestNumber}
```

Example: `https://workflow.{{APP_DOMAIN}}/request/REQ-2025-12-0013`

### Company Name
Replace `[CompanyName]` with your organization name (e.g., "Royal Enfield")

### Date/Time Format
Recommended format:
- Date: `MMM DD, YYYY` (e.g., Dec 04, 2025)
- Time: `HH:MM AM/PM` (e.g., 02:30 PM)
- Duration: Human-readable (e.g., "2 days 5 hours")

### Email Queue Implementation
Use a priority queue system (e.g., Bull/BullMQ) with priority levels:
- Critical: Priority 1
- High: Priority 2
- Medium: Priority 3
- Low: Priority 4

---

## 📊 Template Usage Matrix

| Scenario | Template | Recipients | Priority | Send When |
|----------|----------|-----------|----------|-----------|
| Request Created | RequestCreated | Initiator | High | Immediate |
| Assigned to Approver (Single) | ApprovalRequest | Approver | High | Immediate |
| Assigned to Approver (Multi) | MultiApproverRequest | Approver | High | Immediate |
| Request Approved | ApprovalConfirmation | Initiator | High | Immediate |
| Request Rejected | RejectionNotification | Initiator | Critical | Immediate |
| TAT 80% Elapsed | TATReminder | Approver | High | At 80% TAT |
| TAT Breached | TATBreached | Approver, Mgmt | Critical | Immediate |
| Workflow Paused | WorkflowPaused | All | Medium | On Pause |
| Workflow Resumed | WorkflowResumed | All | High | On Resume |
| Participant Added | ParticipantAdded | New Participant | Medium | On Addition |
| Approver Skipped | ApproverSkipped | All | Medium | On Skip |
| Request Closed | RequestClosed | All Participants | Low | On Closure |

---

## ✅ Quality Checklist

Before sending any email:
- [ ] All placeholders replaced with actual data
- [ ] ViewDetailsLink contains correct request URL
- [ ] Dynamic sections properly rendered or removed
- [ ] Priority-based styling applied correctly
- [ ] Recipient list is accurate
- [ ] Email subject is descriptive
- [ ] From address is configured correctly

---

## 🔐 Security Considerations

1. **URL Validation**: Ensure ViewDetailsLink only contains your domain
2. **Data Sanitization**: Escape HTML in user-provided content (names, comments, descriptions)
3. **Email Spoofing**: Use SPF, DKIM, and DMARC records
4. **Unsubscribe**: Add unsubscribe link if required by regulations
5. **Privacy**: Don't include sensitive data in URLs or plain text

---

**Last Updated:** December 4, 2025  
**Template Version:** 2.0  
**Total Templates:** 12

