Home

Awesome

UPDATE: DEPRECATED. USE https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ses.CfnTemplate.html

SES Templated Emails Helper Constructs for AWS CDK

Why

Features

SES Features

Pre-requisites

Use

import { SESEmailTemplate, SESTemplateMailer } from 'cdk-ses-template-mailer';

// Read from files
new SESEmailTemplate(this, 'Email1', {
    TemplateName: 'mytemplate',
    TextPart: fs.readFileSync(__dirname + '/../ses-templates/mytemplate/template.txt', 'utf8'),
    HtmlPart: fs.readFileSync(__dirname + '/../ses-templates/mytemplate/template.html', 'utf8'),
    SubjectPart: 'Email Subject Goes Here'
});

// Or embed
new SESEmailTemplate(this, 'EventLiveEmail', {
    TemplateName: 'eventLive',
    TextPart: 'Hi {{guest.name}}, {{data.event_title}} is Live!',
    HtmlPart: '<strong>Hi {{guest.name}}</strong><br />{{data.event_title}} is Live!',
    SubjectPart: '{{data.event_title}} is Live!'
});

// ... define more templates....

const mailer = new SESTemplateMailer(this, 'Mailer', {
    FromEmail: 'support@mydomain.com',
    FromName: 'My Service',
    RenderFailuresNotificationsEmail: 'myemail@gmail.com' // optional. add your email to receive render failure notifications
});

new cdk.CfnOutput(this, 'SQSQueueURL', {
    value: mailer.queue.queueUrl
})

new cdk.CfnOutput(this, 'SNSRenderFailureTopicArn', {
    value: mailer.snsRenderFailuresTopic.topicArn
})

Adding SNS subscriptions to other email event types

import { SESSNSDestination } from 'cdk-ses-template-mailer';

const newTopic = new sns.Topic(this, 'CustomEmailEventsTopic', {
    topicName: 'sesSendConfigRenderFailures'
});

new sns.Subscription(this, 'CustomEmailEventsTopicSubscription', {
    topic: newTopic,
    protocol: sns.SubscriptionProtocol.EMAIL,
    endpoint: 'myemail@gmail.com'
})

new SESSNSDestination(this, 'CustomEmailEventsTopicSNSDestination', {
    ConfigurationSetName: 'SendConfig', // Keep it
    EventDestinationName: 'CustomEventsSNSDestination',
    MatchingEventTypes: [
        'send' | 'reject' | 'bounce' | 'complaint' | 'delivery' | 'open' | 'click' | 'renderingFailure'
    ],
    TopicARN: newTopic.topicArn
})

SQS Message format

export interface SESTemplateMailerEventBody {
    to: {
        name?: string,
        email: string
    },
    data: any,
    template: string // name of template
}

Test

aws sqs send-message --queue-url=QUEUE_URL_FROM_OUTPUTS --message-body='{ "data": {}, "template": "mytemplate", "to": { "email": "destination@gmail.com", "name": "Name" }}'

TODO

Useful commands

License

MIT