How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Reading Time: 13 minutes

If you are developing an application that needs to send bulk emails to larger communities for trigger-based messages such as email verification or password resets, announcements like festival discounts, newsletters, or general notifications in a cost-effective, flexible, and scalable manner, then Amazon SES is the answer.

Amazon SES can be used for a variety of use cases like transactional, marketing, or mass email communications. It is a cost-effective and scalable service that provides the flexibility to send mail from within any application. Amazon SES allows us to define Email Templates for the emails that are to be rolled out to different email addresses. The service can also be integrated with any of the external applications, one of which is the use case that we will be going through in this blog.

Amazon SES can be scaled easily and securely with the flexibility to optimize deliverability and send messages efficiently. In this blog, we will see how we can perform operations like the creation or deletion of Email Templates from the Amazon Simple Email Service – SES dashboard using Node.js and Postman API.

In this blog, we’ll cover:

  • What is Amazon Simple Email Service?
  • Benefits of Amazon Simple Email Service
  • Use cases of Amazon Simple Email Service
  • Amazon Simple Email Service Vs Amazon Simple Notification Service
  • Hands-on
  • Companies using Amazon Simple Email Service
  • Conclusion

What is Amazon Simple Email Service (SES)?

SES (Amazon Simple Email Service) is a low-cost, flexible, and scalable email service that empowers developers to send emails from within any application. SES (Amazon Simple Email Service) is a low-cost, flexible, and scalable email service that empowers developers to send emails from within any application.  Amazon SES can be readily configured to assist several email use cases, including transactional, marketing, and mass email communications. Amazon SES’s customizable IP deployment and email authentication options provide improved deliverability and safeguard sender reputation, while analytics gauge the impact of each mail. You can send emails securely, globally, and at scale with Amazon SES.

Benefits of Amazon Simple Email Service (SES)

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Raising a large-scale email solution for a firm can be a difficult and expensive task: you must establish your infrastructure, set up your network, warm up your IP addresses, and secure your sender’s reputation. Several third-party email solutions demand contract negotiations and considerable up-front costs. Amazon SES resolves these hurdles, letting you deliver emails in minutes. It has the following benefits:

  • High Deliverability
  • Cost-Effective
  • Send Emails Efficiently
  • Configurable
  • Scale Securely
  • Reliable

Use Cases of Amazon Simple Email Service (SES)

  • Sending Transaction Messages: Amazon SES serves out automated emails from your application to customers such as order confirmations, shipment notifications, password resets and policy change updates.
  • Sending Marketing Communications: Amazon SES is an excellent tool for distributing advertisements, newsletters, and special offers, with customized content and email templates.
Use Cases of Amazon Simple Email Service (SES)
  • Bulk Email Communication: Sending mass communications to large communities, such as notifications including system health reports, application alerts, workflow status updates and announcements, and monitoring results with configuration sets is all possible with Amazon SES.
  • Receiving Emails: By closing the loop on the email application, emails can be accepted with the help of Amazon SES. AWS Lambda can be used to execute custom code when emails arrive. The queued emails will be delivered to an Amazon S3 bucket.

Amazon Simple Email Service Vs Amazon Simple Notification Service

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Amazon SES is an email-sending service for bulk and transactional emails. The difficulty and cost of developing an in-house email solution or licensing, implementing, and managing a third-party email service are eliminated with Amazon SES. The service interfaces with other AWS services, making it simple to send emails from applications hosted on Amazon EC2-like services.

Whereas, Amazon SNS is a fully managed push messaging service. Pushing to mobile devices like the iPhone, iPad, Android, Kindle Fire, and other internet-connected smart devices, as well as pushing to other distributed services, is straightforward and inexpensive using Amazon Simple Notification Service. In addition to pushing cloud notifications directly to mobile devices,  SNS can send alerts by SMS text message or email, to Simple Queue Service (SQS) queues, or to any HTTP endpoint as well.

Primarily, Amazon SES gets classified under the “Transactional Email” category of the tech stack while Amazon SNS gets categorized under “Mobile Push Messaging”.

Hands-on

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

In this hands-on, we will see how we can make use of Node.js and Postman API to create an Email Template on the Amazon SES dashboard and delete an existing template from the Amazon SES dashboard. We will also have a look at different scenarios altering the code base as required.

We will first create a new directory on the local machine to create our code base in it. Performing the installation of the package.json file, we’ll install the required packages ie. express and aws-sdk. We will then navigate to the package.json file to verify the installation of the packages. Altering the folder structure, we will create a new directory with a file that will store the required AWS AccessKey and SecretKey to be able to communicate with the Amazon Simple Email Service – SES. These credentials will then be exported to be used in our code base. Post that we will navigate to the AWS console, login to our account, and navigate to the IAM dashboard. Editing the IAM user, we will create an AccessKey and SecretKey that is to be stored in the code base.

In the credentials file, we will store the keys and the AWS region. Then we will create the main file that will consist of the main code to create and delete the Email templates from the Amazon SES dashboard. Post adding the required code to create an Email template, we will navigate to the Postman application and store the keys, the region, and the service name under the AWS Signature section so that Postman can communicate to the SES service on hitting a URL. We will then test out the template creation function using Postman. Navigating to the Amazon SES dashboard, we will verify if the template creation was successful. Post that we will alter the code base and the API calls to be able to delete an existing Email Template. Navigating to the Postman application, we will verify the deletion process by cross-verifying through the Amazon SES dashboard.

Finally, we will test out the different scenarios modifying the code further to be able to achieve the results for the same. We will verify the same process via Postman and Amazon SES dashboard and at last, we will have a look at how we can merge the multiple API calls into one API call and have a look at how we can perform the same operations via hitting the URL from any of the browsers.

To perform the implementation, we will do the following:

  • Create a new directory onto the local machine and execute the command to create a package.json file in the directory.
  • Execute the installation command for installing express into the same directory.
  • Open the directory in a code editor and verify the package installation in the package.json file.
  • Install aws-sdk using the command shown below to be able to communicate with the Amazon Simple Email Service.
  • Verify the aws-sdk installation in the package.json file.
  • Alter the folder structure creating a new directory inside which a new file is to be created that will export the AWS credentials to be able to communicate to the Service.
  • Login and navigate to the AWS dashboard.
  • Search for the IAM service and enter the edit mode of an IAM user.
  • Enter the Security credentials section and create an Accesskey and a Secretkey that will be stored in the code base.
  • Store the Accesskey and Secret key in the credentials file along with the AWS Region.
  • Follow the steps and alter the main code file with a function to communicate with the Amazon SES Service and create a new Email Template within it.
  • Navigate to the Postman Application and configure the AWS Accesskey and Secretkey fetched above along with the region and service name.
  • Hit the provided url to create a new template.
  • Navigate to the Amazon SES service dashboard and verify the template creation under the Email Templates section.
  • Navigate back to the code base and alter the code to perform the deletion of a template operation.
  • Switch back to the Postman Api and use the new url to test out the deletion of a template operation.
  • Go back to the Amazon SES service dashboard and cross verify the deletion completion process.
  • Alter the api calls using the steps shown below and then test out the new api calls for creation and deletion processes via Postman API.
  • Merge multiple API calls into a single API call to be able to create and delete the email template at the same time using the code provided below.
  • Finally, test out the creation and deletion operations via hitting the url from any of the browsers.

Create a new folder on your local machine and open Git Bash or cmd in that directory. Execute the command npm in it. Enter a package name and hit enter.

We can leave the other settings as default.

Verify the configurations and type in yes and hit enter.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Now, execute the command npm install express. On successful installation, you will see the message as shown in the image below.

Now, open the directory in a code editor. Create a new file with the name index.js. On success, you will see the new file created in the folder structure.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Now, we need to install aws-sdk to link to the Amazon Simple Email Service so that we can store the templates in it. Execute the command npm install aws-sdk.

On success, open the package.json file and verify the package installation.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

In the folder structure, create a new folder with the name config. Inside the config folder, create a new file with the name aws.js.

Paste the below content inside the aws.js file. We need the following details to connect to the AWS SES Service.

Log in to the AWS Console and navigate to the homepage.

Search for the IAM service and click on it to navigate to the service dashboard.

You will be navigated to the IAM dashboard. Click on Users in the left navigation pane.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Select the user you are logged in with and click on it. On the following page, click on the Security credentials tab.

Scroll down and click on Create Access Key.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Download the .csv file for the access key and secret access key. Copy both the keys.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Navigate back to the code editor. In the index.js file, paste the below code.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Run the code base using the command below.

node .\index.js

You will see the output screen as shown in the image below.

On hitting the URL on localhost:3000 in any browser, you will see the following output.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Now, we need to create a function that will help us create a template on the Amazon SES service. To do so, copy the below code and paste it into the index js file in your code base.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Alter the API call to call the function of the template creation. Make the changes in the index.js file as shown in the code below.

Now, we need to hit the API. To do so, we’ll make use of Postman. You can do so via a browser as well. Switch on the Postman API application. Create or login to your account and click on the plus icon to create a new tab.

In the new tab, click on the Authorization section below.

Select the Type dropdown and choose AWS Signature.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

Enter in the Accesskey and the SecretKey that we fetched above. Enter the AWS Region and select the service name as ses.

Navigate back to the code terminal and execute the below command to start the server.

node .\index.js

Switch back to the Postman API application and in the URL tab, enter the URL as http://localhost:3000/ and click on Send.

If the creation of the template was successful, it would show the message as shown in the image below.

Navigate back to the AWS console and search for the Amazon SES service. Click on it to navigate to its dashboard.

Select Email templates in the left navigation bar.

You will notice that the new template is created with the name that we had defined in our code base.

Now, let’s assume a scenario where you wish to delete a template. In that case, you can use the below code adding it to the same code base.

To execute the delete template scenario, we need to create an API call to perform that operation thereby passing the name of the template that is to be deleted as of a parameter. Thus, we changed the code as shown below.

Navigate back to the Postman application and in the URL, make a call to the /delete path. (ie. http://localhost:3000/delete).

If it’s successful, you will see the message as shown below.

Navigate back to the Amazon SES dashboard and refresh the page. You will see that the same template is now deleted.

Now, since we changed the path for template creation as well, let’s try out the new path. Enter the URL as http://localhost:3000/create and click on Send.

On success, you will see the message as shown in the image below.

Navigate back to the Amazon SES dashboard and refresh the page. You will now see the template created.

Let’s consider a scenario wherein you have made a few changes in the existing template and you wish to deploy those changes. In that case, you would first need to delete the existing template and then create the modified one again with the same name. To ease the process, we can integrate the delete process into the creation process and perform both the operations at a single time with one API call. ie. We can call the deleteExistingTemplate function inside the createAmazonSESTemplate function and hit only the /create API call.

How to create and delete Email Templates on Amazon SES using Node.js and Postman API?

If the deletion of a template were to be performed via any browser, then you could use the URL as https://localhost:3000/delete.

If the creation of a template were to be performed via any browser, then you could use the URL as https://localhost:3000/create.

To use the code that we used for this hands-on, you can clone the below repository:

https://github.com/workfall/Amazon-SES-Email-Templates.git

Companies using Amazon Simple Email Service

Companies using Amazon Simple Email Service

Conclusion

In this hands-on, we saw how we can make use of Node.js and Postman API to create an Email Template on the Amazon SES dashboard and delete an existing template from the Amazon SES dashboard. We also had a look at different scenarios altering the code base as required.

We first created a new directory on the local machine for creating our code base in it. Performing the installation of the package.json file, we installed the required packages ie. express and aws-sdk. We then navigated to the package.json file to verify the installation of the packages.

Altering the folder structure, we created a new directory with a file that stored the required AWS AccessKey and SecretKey to be able to communicate with the Amazon Simple Email Service – SES.

These credentials were then exported to be used in our code base. Post that we navigated to the AWS console, login to our account, and navigated to the IAM dashboard. Editing the IAM user, we created an AccessKey and SecretKey that was to be stored in the code base. In the credentials file, we stored the keys and the AWS region.

Then we created the main file that consisted of the main code to create and delete the Email templates from the Amazon SES dashboard.

After adding the required code to create an Email template, we navigated to the Postman application and stored the keys, the region, and the service name under the AWS Signature section so that Postman can communicate to the SES service on hitting a URL.

We then tested out the template creation function using Postman. Navigating to the Amazon SES dashboard, we verified if the template creation was successful. Post that we altered the code base and the API calls to be able to delete an existing Email Template. Navigating to the Postman application, we verified the deletion process by cross-verifying through the Amazon SES dashboard.

Finally, we tested out the different scenarios modifying the code further to be able to achieve the results for the same.

We then verified the same process via Postman and Amazon SES dashboard and at last, we had a look at how we can merge the multiple API calls into one API call and also had a look at how we can perform the same operations via hitting the URL from any of the browsers.

We will discuss more such use cases in our upcoming blogs. Stay tuned to keep getting all updates about our upcoming new blogs on AWS and relevant technologies. 

Meanwhile …

Keep Exploring -> Keep Learning -> Keep Mastering

This blog is part of our effort towards building a knowledgeable and kick-ass tech community. At Workfall, we strive to provide the best tech and pay opportunities to AWS-certified talents. If you’re looking to work with global clients, build kick-ass products while making big bucks doing so, give it a shot at workfall.com/partner today.

Back To Top