How to use AWS SES (Simple Email Service) with NodeJS?

Rushank Shah
4 min readJun 10, 2022

--

Introduction

What is AWS SES?

Amazon Simple Email Service (SES) is a cost-effective, flexible, and scalable email service that enables developers to send mail from within any application. You can configure Amazon SES quickly to support several email use cases, including transactional, marketing, or mass email communications. Amazon SES’s flexible IP deployment and email authentication options help drive higher deliverability and protect sender reputation while sending analytics to measure the impact of each email. With Amazon SES, you can send email securely, globally, and at scale. — AWS Official Documentation

What is NodeJS?

NodeJS is an open-source server environment that can run on many platforms like Windows and macOS. It uses Javascript as the programming language and is quite performant because of its asynchronous architecture.

What are we going to do?

In this article, we will be learning how to send an Email from AWS SES via NodeJS.

Initial Setup

The first step is to create an AWS account and then create a new user in the AWS account with appropriate rights. (This is a very important step). Giving appropriate rights to users is very important because you don’t want someone with excessive rights to misuse the database. More information on how to add roles to IAM users is here.

Let’s Go

For sending mails through SES, you need to create a Verified Identity. This identity can be of two types, namely, email based and domain based. In this article we will understand the email based identity.

Go to AWS Console and then search for AWS SES.

In the SES management, click on Create Identity and enter your email address

Once you are done, click on create identity and then you will see a page which shows that the identity status is unverified.

For the email address you have entered, you will receive an email for verifying that account. Click on the link and verify the account.

Once verified, refresh the page and the identity status should change to verified.

Now all the setup on AWS is complete.

Let’s move to code!

For ease of use we will using an npm package called “node-ses” for sending emails through NodeJS. This package makes it very simple to use SES and gives a lot of functionalities to use in NodeJS.

The setup of NodeJS is quite simple. You just enter the AccessKey and the Access Secret of the IAM user created in the initial step and you are all ready!

You need to first create a new client to send any email. You can create a new client like this:

After creating this client, you can send an email using the sendEmail function of the client like this:

That’s it! It’s this simple to send 1000’s of email using AWS SES.

This method and library is very simple and abstract compared to what we get in aws-sdk. The node-ses library has a lot more functions and the process gets much easier with the library compared to what you get from SDK provided by AWS. Therefore, I highly recommend everyone to use this library, unless it’s very necessary to use the AWS SDK.

Conclusion

In this short blog, we get a lot to know about how to work with NodeJS and AWS SES. Here is the sample repository which I used in this demo. You can do much more with the library like CC and BCC.

Thank you for reading!

Happy Coding :)

--

--

No responses yet