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

sesemailsenderv3

v1.1.1

Published

A Node.js library for sending emails using AWS SES SDK v3 with S3 attachments.

Downloads

361

Readme

AWS Email SES Sender

AWS Email Sender is a versatile library for sending emails using AWS SES (Simple Email Service) and optionally attaching files from S3. It also supports sending emails using Nodemailer for attachments.

Features

  • Send emails with or without attachments.
  • Fetch email templates and attachments from S3.
  • Supports both AWS SES SDK v3 and Nodemailer for email delivery.
  • Easy-to-configure AWS region and credentials.

Installation

Install the package using npm:

npm install SESEmailSenderV3

Usage Example

Import and Initialize

Basic Usage Without attachements

const { sendEmail } = require('SESEmailSenderV3');

const awsConfigParams = {
  region: 'us-east-1',
  credentials: {
    accessKeyId: 'your-access-key',
    secretAccessKey: 'your-secret-key',
  },
};

const emailParams = {
  FromEmailAddress: '[email protected]',
  ToAddresses: ['[email protected]'],
  Subject: 'Hello from AWS Email Sender',
  BodyTemplate: 'email-template.html',
  BucketName: 'my-email-templates',
  BodyData: {
    name: 'John Doe',
  },
};

sendEmail(emailParams, awsConfigParams)
  .then((response) => console.log('Email sent successfully!', response))
  .catch((error) => console.error('Failed to send email:', error));

Advanced Usage Without attachements

const { sendEmail } = require('sesemailsenderv3');


async function triggerEmail() {
    try {
        let params = {
            FromEmailAddress: '[email protected]', // Verified email in SES
            ToAddresses: ['[email protected]'], // List of recipient emails
            Subject: 'Hello from SES Email Sender',
            BucketName: 'your-s3-bucket-name', // (Optional) S3 bucket for email template
            BodyTemplate: 'your-email-template.html', // (Optional) S3 object key for the email template
            CcAddresses: ['[email protected]'], // (Optional) List of CC emails
            AttachmentBucketName: 'your-s3-bucket-for-attachments', // (Optional) S3 bucket for attachments
            BodyData: {
                name: 'John Doe',
                orderNumber: '123456',
                product: 'Awesome Product'
            }, // (Optional) Placeholder data for the email template
            attachmentKeys: ['attachment1.pdf', 'attachment2.png'] // (Optional) Keys for attachments in S3
        };

        let awsConfig = {
            region: 'ap-south-1', // AWS region for S3 and SES
            credentials: {
                accessKeyId: 'your-access-key-id', // Your AWS Access Key ID
                secretAccessKey: 'your-secret-access-key' // Your AWS Secret Access Key
            },
            sesRegion: 'ap-southeast-1', // (Optional) Specific region for SES
            s3TemplateRegion: 'ap-south-1', // (Optional) Specific region for S3 templates
            s3AttachementsRegion: 'ap-south-1' // (Optional) Specific region for S3 attachments
        };

        // Send the email
        await sendEmail(params, awsConfig);
        console.log('Email sent successfully!');
    } catch (error) {
        console.error('Error sending email:', error);
    }
}

// Trigger the email
triggerEmail();

Parameters

Email Parameters

| Parameter | Type | Description | Required | |------------------------|------------|-----------------------------------------------------------------------------------------------|----------| | FromEmailAddress | string | Sender's email address. Must be verified in SES. | Yes | | ToAddresses | string[] | Array of recipient email addresses. | Yes | | Subject | string | Email subject. | Yes | | CcAddresses | string[] | (Optional) Array of CC email addresses. | No | | BucketName | string | (Optional) Name of the S3 bucket containing the email body template. | No | | BodyTemplate | string | (Optional) Key of the S3 object for the email body template. | No | | BodyData | object | (Optional) Key-value pairs to replace placeholders in the email template. | No | | AttachmentBucketName | string | (Optional) Name of the S3 bucket containing email attachments. | No | | attachmentKeys | string[] | (Optional) Keys of attachments in S3 to include in the email. | No |

AWS Config Parameters

| Parameter | Type | Description | Required | |----------------------------|------------|-------------------------------------------------------------------|----------| | region | string | AWS region for the default configuration. | Yes | | credentials | object | AWS credentials (accessKeyId and secretAccessKey). | No | | sesRegion | string | (Optional) Specific region for SES service. | No | | s3TemplateRegion | string | (Optional) Specific region for S3 templates. | No | | s3AttachementsRegion | string | (Optional) Specific region for S3 attachments. | No |


Example Email Template in S3

An example HTML template file in your S3 bucket:

<!DOCTYPE html>
<html>
<head>
    <title>Email Template</title>
</head>
<body>
    <h1>Hello, {{name}}</h1>
    <p>Your order number is {{orderNumber}} for {{product}}.</p>
</body>
</html>

Notes

  • Ensure that the FromEmailAddress is verified in SES, especially in the sandbox environment.
  • The ToAddresses and CcAddresses must also be verified in the SES sandbox environment or you need production access to send mails.
  • Attachments must be accessible in the specified S3 bucket.