Email Request

Event representing a request to send an email

Event Channel:AWS SQS

Overview

The Email Request event represents a request to send an email. This event is published to the Email Queue and consumed by the Email Sender service, which sends emails using AWS SES.

Payload

The payload contains email sending instructions:

Email Request Payload
{
"to": "string | string[]",
"subject": "string",
"body": "string",
"templateId": "string (optional)",
"templateData": {
// Template variables
},
"from": "string (optional)",
"cc": "string[] (optional)",
"bcc": "string[] (optional)"
}

Producing the Event

Email requests are published to the Email Queue by various services:

  1. Notification Services: For sending notifications
  2. Confirmation Services: For sending confirmations
  3. Follow-up Services: For sending follow-up emails
  4. System Alerts: For sending system alerts
Publishing Email Request
import { SQSClient } from './clients/sqs-client';
const sqsClient = new SQSClient();
await sqsClient.sendMessage({
to: 'customer@example.com',
subject: 'Appointment Confirmation',
body: 'Your appointment has been confirmed...',
templateId: 'appointment-confirmation',
templateData: {
customerName: 'John Doe',
appointmentDate: '2024-01-20',
appointmentTime: '10:00 AM'
}
}, 'email');

Consuming the Event

The event is consumed by the emailSender Lambda function:

Processing Email Request
export const handler = async (event: SQSEvent): Promise<SQSBatchResponse> => {
return sqsBatchProcessor<EmailPayload>({
schema: EmailPayloadSchema,
processPayload: async (payload, appContext) => {
const emailService = appContext.get(EmailService);
await emailService.sendEmail(payload);
},
})(event);
};

Email Types

  • Transactional Emails: Order confirmations, appointment confirmations
  • Notification Emails: System notifications, alerts
  • Confirmation Emails: Account confirmations, password resets
  • System Alerts: Error notifications, system status updates

Template Support

The service supports email templates using Handlebars. Templates can be stored and rendered with dynamic data.

Event-driven architecture documentation: Impulsell