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

ses-easy-mailer

v1.0.4

Published

A simple and easy-to-use mailer module for Amazon SES.

Downloads

10

Readme

SES Easy Mailer

A simple and easy-to-use mailer module for Amazon SES.

Installation

npm install ses-easy-mailer

Usage

const { createTransporter, sendMail } = require('ses-easy-mailer');
const { SESClient } = require('@aws-sdk/client-ses');

const client = new SESClient(
    region: "us-east-1",
    credentials: {
        accessKeyId: "",
        secretAccessKey: "",
    }
);
const transporter = createTransporter(client);

One of the key features of the SES Easy Mailer module is its support for both file and SES templates. This gives developers the flexibility to choose the method that best suits their needs.

Using a file Template

If you prefer to keep your email templates as HTML files in your project, you can do so and SES Easy Mailer will handle the loading and rendering of these templates. This is great for developers who like to keep their templates version controlled with their code.

Here's an example of how to send an email using a file template:

const from = '[email protected]';
const to = '[email protected]';
const subject = 'Hello, world!';
const templateType = 'file';
const templatePath = './template.html';
const templateData = { name: 'John Doe' };
const attachments = [];

await sendMail(
    transporter,
    from,
    subject,
    templateType,
    templatePath,
    templateData,
    attachments,
    to
)

In this example, template.html is a HTML file with placeholders in the format {{ placeholder }} . The templateData object is used to replace these placeholders with actual data.

Using SES Template

const templateType = 'ses';
const templateName = 'ses-template-name'; // The name of the template you created in SES

await sendMail(
    transporter,
    from,
    subject,
    templateType,
    templateName,
    templateData,
    attachments,
    to
)

If you are sending an SES template without attachments, the module will automatically use the SendTemplatedEmailCommand.

This is to avoid downloading the template with extra http call.

However, it's important to note that you must include all the data associated with the template in templateData. If any data is missing, the email will not be sent, even though AWS might indicate that it was sent successfully.

Attachments

if you want to attach files to your email, you can pass an array of objects to the attachments parameter. Each object must have the following properties:

  • filename: The name of the file to be attached.
  • content (Buffer): The content of the file to be attached.
  • encoding: The encoding of the file data. Defaults to 'base64'.
let buffer = Buffer.from("hello world!", "utf-8");

let attachments = [
    {
        filename: "test.txt",
        content: buffer,
        encoding: "base64",
    }
]

SES Unsupported File Types

SES does not support all file types. If you try to send an email with an unsupported file type, SES will throw an error. You can find a list of supported file types here.