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

aws-ses-mail

v2.1.1

Published

A simple package for sending email from aws ses

Downloads

773

Readme

A nodejs wrapper for aws-ses-sdk to send email NPM version

NPM

This is a simple package for sending email from aws ses. It helps you send email by templates or send a large amount of email.

Quick Examples

$ npm install aws-ses-mail
var awsSesMail = require('aws-ses-mail');

var sesMail = new awsSesMail();
var sesConfig = {
  accessKeyId: 'YOUR ACCESSKEYID',
  secretAccessKey: 'YOUR SECRETACCESSKEY',
  region: 'THE REGION'
};
sesMail.setConfig(sesConfig);

var options = {
  from: 'Sender <[email protected]>',
  to: mailList,
  subject: 'Hello world',
  content: '<html><head></head><body><div><p>Hello world!</p></div></body></html>'
};

sesMail.sendEmail(options, function(data) {
  // TODO sth....
  console.log(data);
});

Installation

$ npm install aws-ses-mail

Usage

Initialize

var awsSesMail = require('aws-ses-mail');

accessKeyId: Required. (String) — your AWS access key ID.

secretAccessKey: Required. (String) — your AWS secret access key.

region: Required. (String) — the region to send service requests to. See region for more information.

var sesConfig = {
  accessKeyId: 'YOUR ACCESSKEYID',
  secretAccessKey: 'YOUR SECRETACCESSKEY',
  region: 'THE REGION'
};
awsSesMail.setConfig(sesConfig);

You also can load config data from json file.

// aws-ses-mail.conf
{
  "accessKeyId": "YOUR ACCESSKEYI",
  "secretAccessKey": "YOUR SECRETACCESSKEY",
  "region": "THE REGION"
};
sesMail.setConfigFromFile('aws-ses-mail.conf');

Send mail

This package support to use email templates. You can use templates by html or jade, and you also can enter the content by youself.

The ses mail limit is 50 recipient per process. This package help you to send a large amount of email.

Send simple email

Send email batch

to: (String, String[]) — The destination for this email(to).

cc: (String, String[]) — The destination for this email(cc).

bcc: (String, String[]) — The destination for this email(bcc).

subject: Required. (String) — The subject of the message: A short summary of the content, which will appear in the recipient's inbox.

content: Required. (String) — The message body.

charset: The character set of the subject and the content.

replyToAddresses: (String, String[]) — The reply-to email address(es) for the message. If the recipient replies to the message, each reply-to address will receive the reply.

returnPath: (String) — The email address to which bounces and complaints are to be forwarded when feedback forwarding is enabled. If the message cannot be delivered to the recipient, then an error message will be returned from the recipient's ISP; this message will then be forwarded to the email address specified by the ReturnPath parameter.

callback([err], [results]):

err — the error object returned from the request. Set to null if the request is successful.

results — the de-serialized data returned from the request. Set to null if a request error occurs.

var options = {
  from: 'Sender <[email protected]>',
  to: '[email protected]',
  cc: ['[email protected]', '[email protected]'],
  bcc: '[email protected]',
  subject: 'Hello world',
  content: '<html><head></head><body><div><p>Hello world!</p></div></body></html>'
};

sesMail.sendEmail(options, function(err, data) {
  if (err) {
    console.log(JSON.stringify(err));
    /*
      {"date":"2014-11-03T07:14:41.291Z",
        "receiver":{"ToAddresses":["[email protected]"]},
        "success":false,
        "result":{
          "message":"XXXXX",
          "code":"XXXXX",
          "errno":"XXXXX",
          "syscall":"XXXXX",
          "region":"XXXXX",
          "hostname":"XXXXX",
          "retryable":XXXXX,
          "time":"2014-11-03T07:14:41.291Z"
        }
      }
    */
  } else {
    console.log(JSON.stringify(data));
    /*
      {"date":"2014-11-03T08:21:56.720Z",
        "receiver":{"ToAddresses":["[email protected]"]},
        "success":true,
        "result":
          {"ResponseMetadata":{"RequestId":"XXXXXXXXXXXXXXX"},
          "MessageId":"XXXXXXXXXX"}
        }
      }
    */
});

to: (String, String[]) — The destination for this email(to).

cc: (String, String[]) — The destination for this email(cc).

bcc: (String, String[]) — The destination for this email(bcc).

subject: Required. (String) — The subject of the message: A short summary of the content, which will appear in the recipient's inbox.

template: Required. (String) — The jade template path.

templateArgs: Required. (Json) — The jade template argument, See template for more information.

charset: The character set of the subject and the content.

replyToAddresses: (String, String[]) — The reply-to email address(es) for the message. If the recipient replies to the message, each reply-to address will receive the reply.

returnPath: (String) — The email address to which bounces and complaints are to be forwarded when feedback forwarding is enabled. If the message cannot be delivered to the recipient, then an error message will be returned from the recipient's ISP; this message will then be forwarded to the email address specified by the ReturnPath parameter.

callback([err], [results]):

err — the error object returned from the request. Set to null if the request is successful.

results — the de-serialized data returned from the request. Set to null if a request error occurs.

var options = {
  from: 'Sender <[email protected]>',
  to: '[email protected]',
  cc: ['[email protected]', '[email protected]'],
  bcc: '[email protected]',
  subject: 'Hello world',
  template: 'templates/example.jade',
  templateArgs: {
    name: 'Tester',
    date: '2014/10/31 12:00',
  }
};

sesMail.sendEmailByJade(options, function(err, data) {
  if (err) {
    console.log(JSON.stringify(err));
    /*
      {"date":"2014-11-03T07:14:41.291Z",
        "receiver":{"ToAddresses":["[email protected]"]},
        "success":false,
        "result":{
          "message":"XXXXX",
          "code":"XXXXX",
          "errno":"XXXXX",
          "syscall":"XXXXX",
          "region":"XXXXX",
          "hostname":"XXXXX",
          "retryable":XXXXX,
          "time":"2014-11-03T07:14:41.291Z"
        }
      }
    */
  } else {
    console.log(JSON.stringify(data));
    /*
      {"date":"2014-11-03T08:21:56.720Z",
        "receiver":{"ToAddresses":["[email protected]"]},
        "success":true,
        "result":
          {"ResponseMetadata":{"RequestId":"XXXXXXXXXXXXXXX"},
          "MessageId":"XXXXXXXXXX"}
        }
      }
    */
});

to: Required. (String[]) — The destination for this email.(recipients array)

subject: Required. (String) — The subject of the message: A short summary of the content, which will appear in the recipient's inbox.

content: Required. (String) — The message body.

charset: The character set of the subject and the content.

replyToAddresses: (String, String[]) — The reply-to email address(es) for the message. If the recipient replies to the message, each reply-to address will receive the reply.

returnPath: (String) — The email address to which bounces and complaints are to be forwarded when feedback forwarding is enabled. If the message cannot be delivered to the recipient, then an error message will be returned from the recipient's ISP; this message will then be forwarded to the email address specified by the ReturnPath parameter.

callback([results]):

results — results includes success and failed log, and records date and recipients list.

var options = {
  from: 'Sender <[email protected]>',
  to: ['[email protected]', '[email protected]', '[email protected]'],
  subject: 'Hello world',
  content: '<html><head></head><body><div><p>Hello world!</p></div></body></html>'
};

sesMail.sendEmailBatch(options, function(data) {
  console.log(JSON.stringify(data));
  /*  
    {"date":"2014-11-03T08:36:03.610Z",
      "receiver":["xxxxx@xxxx","xxxxx@XXXX, XXXXX"],
      "successLog":[
        {"ResponseMetadata":{"RequestId":"XXXXXXXX"},
         "MessageId":"XXXXXXXXX",
         "email":"XXXXX@XXXXX"
        },
        {"ResponseMetadata":{"RequestId":"XXXXX"},
         "MessageId":"XXXXXX",
         "email":"XXXXX@XXXXX"
        }
      ],
      "failedLog":[
        {"message":"XXXX",
        "code":"XXXXX",
        "time":"2014-11-03T08:36:06.798Z",
        "statusCode":XXX,
        "retryable":XXXX,
        "email":"XXXX"}
      ]
    }
  */
  }
});

to: Required. (String[]) — The destination for this email(to).

subject: Required. (String) — The subject of the message: A short summary of the content, which will appear in the recipient's inbox.

template: Required. (String) — The jade template path.

templateArgs: Required. (Json) — The jade template argument, See template for more information.

charset: The character set of the subject and the content.

replyToAddresses: (String, String[]) — The reply-to email address(es) for the message. If the recipient replies to the message, each reply-to address will receive the reply.

returnPath: (String) — The email address to which bounces and complaints are to be forwarded when feedback forwarding is enabled. If the message cannot be delivered to the recipient, then an error message will be returned from the recipient's ISP; this message will then be forwarded to the email address specified by the ReturnPath parameter.

callback( [results]):

results — results includes success and failed log, and records date and recipients list.

var options = {
  from: 'Sender <[email protected]>',
  to: ['[email protected]', '[email protected]', '[email protected]'],
  subject: 'Hello world',
  template: 'templates/example.jade',
  templateArgs: {
    name: 'Tester',
    date: '2014/10/31 12:00',
  }
};

sesMail.sendEmailBatchByJade(options, function(data) {
  console.log(JSON.stringify(data));
  /*  
    {"date":"2014-11-03T08:36:03.610Z",
      "receiver":["xxxxx@xxxx","xxxxx@XXXX, XXXXX"],
      "successLog":[
        {"ResponseMetadata":{"RequestId":"XXXXXXXX"},
         "MessageId":"XXXXXXXXX",
         "email":"XXXXX@XXXXX"
        },
        {"ResponseMetadata":{"RequestId":"XXXXX"},
         "MessageId":"XXXXXX",
         "email":"XXXXXX@XXXXXX"
        }
      ],
      "failedLog":[
        {"message":"XXXX",
        "code":"XXXXX",
        "time":"2014-11-03T08:36:06.798Z",
        "statusCode":XXX,
        "retryable":XXXX,
        "email":"XXXX"}
      ]
    }
  */
  }
});

Jade example

templateArgs: {
  name: 'Tester',
  date: '2014/10/31 12:00',
}
doctype html
html
  head
  body
    div
      p Hi #{name}
      p This is a test email template.
      p #{date}

Html example

templateArgs: {
  name: 'Tester',
  date: '2014/10/31 12:00',
}
<html>
  <head></head>
  <body>
    <div>
      <p>Hi, #{name}</p>
      <p>This is a test email template.</p>
      <p>#{date}</p>
    </div>
  </body>
</html>

Example

you can find the full example in /example folder.

AWS SES SDK document

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/frames.html#!AWS/SES.html