Sending Emails with AWS SES and Nodemailer in Node.js

Sending emails is a common task in web applications, and various services are available to handle this.

You probably heard of SES (Simple Email Service) if you are an AWS user. If not, SES is a popular and scalable email-sending service by Amazon.

This tutorial will demonstrate how to set up and use AWS SES with Nodemailer in a Node.js project to send emails.

A letter form AWS


  • An AWS account
  • Node.js and npm installed on your machine

Step 1: Set up AWS SES

  • Sign in to your AWS account.
  • Go to the SES Console:
  • Choose the region you want to use for SES (I'm using eu-west-1 in this example so make sure you swap your region in).
  • Verify the email address or domain you'll be sending emails from and the domain or emails you will be sent to for testing.
  • Optional step (not required for the demo). Request production access to increase your sending limits, if needed (this lifts the restriction on the number of emails you can send and the emails you can send to).

Step 2: Install the required packages

Run the following command in your project folder:

npm install nodemailer @aws-sdk/client-ses dotenv

Step 3: Configure AWS credentials

Create a new IAM user with AmazonSESFullAccess permission, and obtain its AccessKeyId and SecretAccessKey.

Set the AWS credentials using environment variables or an AWS credentials file. For environment variables, set ACCESS_KEY and SECRET_ACCESS_KEY in your .env file or your server environment.

For this example I'll use a .env file.

Example of a .env file:


Step 4: Set up Nodemailer with AWS SES

Create a new file, e.g., sendMail.mjs, and import the required packages and configure Nodemailer with AWS SES. I'm using a .mjs file extension so that I can use the import syntax with Node.js for testing it.

// sendMail.mjs
import nodemailer from "nodemailer";
import * as aws from "@aws-sdk/client-ses";
// So we can use .env variables locally import dotenv
import * as dotenv from 'dotenv' 


const ses = new aws.SES({
  apiVersion: "2010-12-01",
  region: "eu-west-1", // Your region will need to be updated
  credentials: {
    accessKeyId: process.env.ACCESS_KEY,
    secretAccessKey: process.env.SECRET_KEY,

// create Nodemailer SES transporter
const transporter = nodemailer.createTransport({
  SES: { ses, aws },

const sendMail = () => {
  // send mail
      // mail options
        from: "", // replace with your own address
        to: "", // replace with your own address
        subject: "Testing my Nodemailer/SES setup",
        text: "This is a message to say you did it!",
      // callback
      (error, info) => {
        if (error) {
          console.error('Error sending email:', error);
        } else {
          console.log('Email sent:', info.messageId);

export default sendMail;

Replace the from/to email addresses, region, and email content with your own. Run the sendMail function directly from the CLI with node.js to test it:

node -e "import('./sendMail.mjs').then(module => module.default());"

When you run this command you should see something like:

Email sent: <>

Note: The -e flag lets us write JavaScript in the command line. This just lets me write the file in a way that's easy for you to import into any other file in your application and start sending mail.

This will send an email using AWS SES and Nodemailer. You can adjust the code according to your specific requirements.

Check out the nodemailer docs here for more information on creating more sophisticated emails.

Let me know below if this helped or if you run into any issues. 👇

Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses; Lead Developer, Software Architect, Product Manager, CTO and now happily a Founder.


Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.