/** * Deploy SES Templates to AWS * * Run this script to create or update the email templates in AWS SES. * Usage: npx ts-node scripts/deploy-templates.ts */ import { SESv2Client, CreateEmailTemplateCommand, UpdateEmailTemplateCommand } from "@aws-sdk/client-sesv2"; const sesClient = new SESv2Client({ region: process.env.AWS_SES_REGION || "us-east-1", }); const APP_NAME = "Elmeg"; const SUPPORT_EMAIL = "support@elmeg.xyz"; // Template definitions const templates = [ { TemplateName: "ELMEG_EMAIL_VERIFICATION", TemplateContent: { Subject: "Verify your Elmeg account", Html: `

{{app_name}}

Verify your email address

Hi {{user_name}},

Thanks for signing up for {{app_name}}. Please verify your email address by clicking the button below.

Verify Email Address

This link will expire after 24 hours for your security.

If you did not create an account, you can safely ignore this email.


If the button above doesn't work, copy and paste this URL: {{verification_link}}

{{app_name}} • Contact: {{support_email}}

`, Text: `Verify your Elmeg account Hi {{user_name}}, Thanks for signing up for {{app_name}}. Please verify your email address by clicking the link below: {{verification_link}} This link will expire after 24 hours for your security. If you did not create an account, you can safely ignore this email. --- {{app_name}} • Contact: {{support_email}}`, }, }, { TemplateName: "ELMEG_PASSWORD_RESET", TemplateContent: { Subject: "Reset your Elmeg password", Html: `

{{app_name}}

Reset your password

Hi {{user_name}},

We received a request to reset the password for your {{app_name}} account. Click the button below to choose a new password.

Reset Password

This link will expire after 1 hour for your security.

If you did not request a password reset, you can safely ignore this email.


If the button above doesn't work, copy and paste this URL: {{reset_link}}

{{app_name}} • Contact: {{support_email}}

`, Text: `Reset your Elmeg password Hi {{user_name}}, We received a request to reset the password for your {{app_name}} account. Click the link below to choose a new password: {{reset_link}} This link will expire after 1 hour for your security. If you did not request a password reset, you can safely ignore this email. --- {{app_name}} • Contact: {{support_email}}`, }, }, { TemplateName: "ELMEG_SECURITY_ALERT", TemplateContent: { Subject: "Security alert for your Elmeg account", Html: `

{{app_name}}

⚠️ Security Notice

Account activity detected

Hi {{user_name}},

We detected the following activity on your {{app_name}} account:

{{security_event_description}}

If this was you, no further action is needed.

If you did not perform this action, please secure your account immediately.

{{app_name}} • Contact: {{support_email}}

`, Text: `Security alert for your Elmeg account Hi {{user_name}}, We detected the following activity on your {{app_name}} account: {{security_event_description}} If this was you, no further action is needed. If you did not perform this action, please secure your account immediately. --- {{app_name}} • Contact: {{support_email}}`, }, }, ]; async function deployTemplates() { console.log("🚀 Deploying SES email templates...\n"); for (const template of templates) { try { // Try to create the template first const createCommand = new CreateEmailTemplateCommand(template); await sesClient.send(createCommand); console.log(`✅ Created template: ${template.TemplateName}`); } catch (error: unknown) { const err = error as { name?: string }; if (err.name === "AlreadyExistsException") { // Template exists, update it try { const updateCommand = new UpdateEmailTemplateCommand(template); await sesClient.send(updateCommand); console.log(`🔄 Updated template: ${template.TemplateName}`); } catch (updateError) { console.error(`❌ Failed to update ${template.TemplateName}:`, updateError); } } else { console.error(`❌ Failed to create ${template.TemplateName}:`, error); } } } console.log("\n✅ Template deployment complete!"); } deployTemplates().catch(console.error);