JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q34489F
  • License MIT

Send newsletters using AWS SES

Package Exports

  • newsletter-ses

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (newsletter-ses) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

newsletter-ses

Send newsletters using AWS SES

Build Status bitHound Overall Score bitHound Dependencies

Install

npm install --save newsletter-ses

Usage

The configuration format:

const config = {
    "ses": {
        "accessKeyId": "7187fa1fcf3211e6", 
        "secretAccessKey": "7187fa1f-cf32-11e6-8edf+e3d56a8d0e0", 
        "region": "eu-west-1"
    },
    "lists": [
        {
            // The optional newsletter ID
            "id": "newsletter-test-1",
            // The newsletter name. used as fallback dubject
            "name": "Newsletter Test List #1",
            // The newsletter sender (from)
            "sender": "newsletter@example.com",
            // The list for members
            "members": [
                { "email": "test@example.com" } 
            ],
            // message to send
            "message": {
                "subject": "Hello, World",
                "html": "<p>The newsletter body in HTML</p>",
                "plain": "The newsletter body in Plain Text"
            }
        },
        {
            "id": "newsletter-test-2",
            "name": "Newsletter Test List #2",
            "sender": "newsletter@example.com",
            "members": [ { "email": "test@example.com" } ],
            "message": {
                // Node the missing subject field: 
                // it will be generate from the <title> tag in the HTML content
                "html": `
                    <html>
                        <head>
                            <title>Hello, World!</title>
                        </head>
                        <body>
                            <p>The newsletter body in HTML</p>
                        </body>
                    </html>`,
                "plain": "The newsletter body in Plain Text"
            }
        },
        {
            "id": "newsletter-test-3",
            "name": "Newsletter Test List #3",
            "sender": "newsletter@example.com",
            "members": [ { "email": "test@example.com" } ],
            "message": {
                "html": `
                    <html>
                        <head>
                            <title>Hello, World!</title>
                        </head>
                        <body>
                            <p>The newsletter body in HTML</p>
                        </body>
                    </html>`
                // Note the missing 'plain' field:
                // it will be generate from the HTML content
            }
        },
        {
            "id": "newsletter-test-4",
            "name": "Newsletter Test List #4",
            "sender": "newsletter@example.com",
            "members": [ { "email": "test@example.com" } ],
            // You can pass your message directly as a string.
            // The message.subject and message.plain will be generate
            "message": `
                <html>
                    <head>
                        <title>Hello, World!</title>
                    </head>
                    <body>
                        <p>The newsletter body in HTML</p>
                    </body>
                </html>`
        }
    ]
}

Then:

const newsletter = require('newsletter-ses')

newsletter.configure(config.ses)
    .send(config.lists)
        .on('quota.error', (e) => {
            console.log(`Failed to get send quota`, e)
        })
        .on('start', (e) => {
            console.log(e)
            /*
                ==> 
                { 
                    list: { 
                        // the current list
                    },
                    mail: { 
                        subject: 'Hello, World',
                        html: '<p>The newsletter body in HTML</p>',
                        plain: 'The newsletter body in Plain Text'
                    },
                    sender: 'newsletter@example.com',
                    start: '2016-12-31T17:25:05.380Z'
                }
            */
            
            console.log(`Starting to send emails to ${e.list.members.length} members`)
        })
        .on('batch', (e) => console.log(`batch ${e.iteration}/${e.cycle}`))
        .on('error', (e) => {
            console.log(e)
            /*
                ==> 
                { 
                    list: { ... },              // the current list
                    member: 'user@example.com', // the current user
                    time: 2102.321,             // time of the sending operation in ms
                    report: "...",              // the error stack
                    error: { ... }              // the error object
                }
            */
            
            console.log(`Error when sending an email to ${e.member.email} (${e.time} ms)`)
        })
        .on('sent', (e) => {
            console.log(e)
            /*
                ==> 
                { 
                    list: { ... },              // the current list
                    member: 'user@example.com', // the current user
                    time: 2102.321,             // time of the sending operation in ms
                    report: "...",              // the sucess request result
                }
            */
            
            console.log(`Sent to ${e.member.email} (${e.time} ms)`)
        })
        .on('complete', (e) => {
            console.log(e)
            /*
                ==> 
                { 
                    list: { ... },              // the current list
                    member: 'user@example.com', // the current user
                    time: 16441.023,            // time of the operation in ms
                    report: {
                        list: { ... },          // the current list
                        mail: { ... },
                        sender: 'newsletter@example.com',
                        start: '2016-12-31T17:25:05.380Z',
                        end: '2016-12-31T17:25:21.380Z',
                        sent: [ ... ],          // the list of success members
                        error: [],              // the list of faillure members
                        duration: 16441.023
                    }
                }
            */
            
            console.log(`Finish to send ${e.list.id} (${e.time} ms)`)
        })
        .on('finish', () => console.log(`Finished to send ${config.lists.length} lists`))

License

Under the MIT license. See LICENSE file for more details.