Email Notifications
The platform sends automated email notifications at workflow transition points. All emails are dispatched through an AWS Lambda function connected to AWS SES.
Email Infrastructure
Helper file: src/helpers/send_email.ts
Email dispatch flow:
Application → AWS Lambda → AWS SES → Recipient
(eu-north-1)
All emails are sent from admin@tailoredtech.tech.
Email Payload
interface EmailPayload {
source: string; // Sender email
destination: string; // Recipient email
subject: string; // Email subject
body_html: string; // HTML email body
link?: string; // Direct link to the MOC/PCR
type?: string; // Email category
notify?: boolean; // Also create in-app notification (default: true)
moc?: string; // MOC serial number (for context)
description?: string; // Brief description
}
When notify is true (default), the system also creates an in-app notification by converting the HTML body to markdown via htmlToMarkdown().
MOC Email Events
MOC Creation
- Trigger: New MOC created via
POST /api/newmoc - Recipients: Assigned implementer
- Content: Notification that a new MOC has been assigned with a link
Implementer Approval (Part B)
- Trigger:
POST /api/submit/implementerwith approval - Recipients: HSEQ department email, assigned HSEQ user, approver, all MOC users, originator
- Content: MOC has been assessed and is ready for HSEQ review
Implementer Decline (Part B)
- Trigger:
POST /api/submit/implementerwith decline - Recipients: Originator, all MOC users
- Content: MOC has been declined by the implementer with the stated reason
HSEQ Approval (Part C)
- Trigger:
POST /api/submit/hseqwith approval - Recipients: Approver, originator, implementer
- Content: HSEQ review is complete, MOC is ready for approval
HSEQ Return (Part C)
- Trigger:
POST /api/submit/hseqwith "no" answers - Recipients: Implementer, originator
- Content: HSEQ has returned the MOC for revision
Approver Approval (Part D)
- Trigger:
POST /api/submit/approverwith approval - Recipients: Originator, implementer, HSEQ user
- Content: MOC has been approved, ready for implementation
Approver Decline (Part D)
- Trigger:
POST /api/submit/approverwith decline - Recipients: Originator, implementer, HSEQ user
- Content: MOC has been declined by the approver
Implementation Complete (Part E)
- Trigger:
POST /api/submit/implementation(no deviations) - Recipients: All stakeholders
- Content: Implementation is complete, ready for verification
Deviation/Extension Request (Part E)
- Trigger:
POST /api/submit/implementationwith deviation or extension - Recipients: Approver, HSEQ user
- Content: A deviation or extension has been requested
Verification Complete (Part F)
- Trigger:
POST /api/submit/verifier - Recipients: Originator, implementer, HSEQ user, approver
- Content: MOC has been verified and closed
PCR Email Events
PCR emails use branded HTML templates defined in src/helpers/pcr_email_helpers.ts.
PCR Initiation
- Trigger:
POST /api/pcr - Recipients: VP Fleet Management (by role), all admins, all affected parties
- Template function:
sendPcrInitiationEmails() - Content: New PCR has been created with serial number and link
Next Signature Required
- Trigger:
POST /api/pcr/signatures(after each signature) - Recipients: The next role in the signing chain
- Template function:
sendNextSignatureEmail() - Content: A PCR is awaiting your signature with a direct link
PCR Completion
- Trigger: All signatures collected (both signatures and affected parties)
- Recipients: Originator, all admins
- Template function:
sendPcrCompletionEmails() - Content: PCR has been fully signed and completed
Email Template
PCR emails use a consistent branded template:
function createPcrEmailTemplate() {
// Generates HTML with:
// - Bahri logo header
// - PCR serial number
// - Action description
// - "View PCR" button linking to the platform
// - Footer with timestamp
}
Links in emails point to ${NEXT_PUBLIC_APP_URL}/dashboard/main/allPcr/{pcrId}.