npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cdk-ses-template-mailer

v0.1.15

Published

## Why - AWS SES Templates are amazing but pain to setup and manage

Downloads

17

Readme

SES Templated Emails Helper Constructs for AWS CDK

Why

  • AWS SES Templates are amazing but pain to setup and manage

Features

  • Custom resource to create SES Email Templates (functionality missing in AWS UX and CloudFormation)
  • Custom resource to add SNS destination to message delivery events
  • SNS topic and optional email subscription to notify you of template render fails!
  • Lambda with an SQS queue to send emails without going over your SES limits
  • Easy to drop-in to your project and use right away
  • Perfect for transactional and drip emails
  • 0 idle costs. 100% serverless

SES Features

  • You can create up to 10,000 email templates per Amazon SES account.
  • Each template can be up to 500KB in size, including both the text and HTML parts.

Pre-requisites

  • FromEmail needs to be verified in AWS SES aws ses verify-email-identity --email-address [email protected]
  • Apply for a sending limit increase (https://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html) to be able to send to non-verified email addresses
  • If you include RenderFailuresNotificationsEmail you will receive an "AWS Notification - Subscription Confirmation" email.
  • npm install cdk-ses-template-mailer

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: '[email protected]',
    FromName: 'My Service',
    RenderFailuresNotificationsEmail: '[email protected]' // 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: '[email protected]'
})

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": "[email protected]", "name": "Name" }}'

TODO

  • Explore SendBulkTemplatedEmail (send email to up to 50 destinations in each call)
  • Add automated email tracking and stats collection?
  • Export Message Type
  • Tests

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile

License

MIT