\n\n\n\n How to Integrate Amazon SES with Node.js (Step by Step) \n

How to Integrate Amazon SES with Node.js (Step by Step)

📖 5 min read925 wordsUpdated May 12, 2026

Integrating Amazon SES with Node.js: A Practical Tutorial

We’re building an email-sending application using Amazon SES integration that not only sends emails but also handles errors gracefully and logs activity. This is important because most developers underestimate the complexity of email sending, leading to issues down the line.

Prerequisites

  • Node.js 14+ (LTS)
  • AWS SDK for JavaScript (v3)
  • Amazon SES account with verified email addresses
  • Nodemailer package for email handling

Step 1: Setting Up Your Environment

First, you need to set up your Node.js environment. If you haven’t already, install Node.js. You can check your version by running:

node -v

Once you have Node.js installed, create a new project directory and initialize a new Node.js project:

mkdir ses-email-sender
cd ses-email-sender
npm init -y

This creates a package.json file where all your dependencies will live. Now, let’s install the necessary packages:

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

Why these packages? The AWS SDK allows you to interact with Amazon SES, and Nodemailer simplifies email sending.

Step 2: Configure Your AWS Credentials

Before you can send emails, you need to configure your AWS credentials. Create a new file named .env in your project root:

touch .env

Add your AWS credentials and region to the .env file:

AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_REGION=us-east-1

Make sure to replace your_access_key and your_secret_key with your actual AWS access key and secret key. The region must match the SES settings.

Step 3: Create the Email Sender Function

Now, let’s set up a function that sends emails using Nodemailer and the AWS SES transport. Create a new file named sendEmail.js:

const nodemailer = require('nodemailer');
const { SESClient, SendEmailCommand } = require('@aws-sdk/client-ses');
require('dotenv').config();

const ses = new SESClient({
 region: process.env.AWS_REGION,
 credentials: {
 accessKeyId: process.env.AWS_ACCESS_KEY_ID,
 secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
 },
});

async function sendEmail(to, subject, text) {
 const transporter = nodemailer.createTransport({
 SES: { ses, aws: { region: process.env.AWS_REGION } },
 });

 const mailOptions = {
 from: '[email protected]',
 to,
 subject,
 text,
 };

 try {
 const result = await transporter.sendMail(mailOptions);
 console.log('Email sent:', result);
 } catch (error) {
 console.error('Error sending email:', error);
 }
}

module.exports = sendEmail;

This function sets up the transport using SES and sends an email. You’ll hit some errors if you try to send from an unverified email address. Always ensure that your sender email is verified in your SES account.

Step 4: Testing the Function

Next, you need to test the email sending function. Create a new file named index.js:

const sendEmail = require('./sendEmail');

const main = async () => {
 await sendEmail('[email protected]', 'Test Subject', 'Hello from AWS SES!');
};

main();

Run your test:

node index.js

Keep an eye out for any errors related to permissions or invalid parameters. If you receive an error about unauthorized access, double-check your IAM policies for SES.

The Gotchas

  • Sending Limits: SES has limitations on the number of emails you can send per day unless you request a production access increase. During the sandbox phase, you’re limited to sending emails only to verified addresses.
  • Region Mismatch: If your SES service is in one AWS region, but your code is configured for another, your emails won’t send. Always align the region settings.
  • Unverified Emails: Sending from an unverified email will result in errors. Always verify your sender address in SES.
  • Error Handling: Not catching errors properly can lead to silent failures. Make sure to log errors for easier debugging.
  • Configuration Changes: If you change any environment variables, restart your Node.js application; otherwise, the old variables will persist.

Full Code

Below is the complete working example. Make sure to replace the necessary placeholders with your actual data.

const nodemailer = require('nodemailer');
const { SESClient, SendEmailCommand } = require('@aws-sdk/client-ses');
require('dotenv').config();

const ses = new SESClient({
 region: process.env.AWS_REGION,
 credentials: {
 accessKeyId: process.env.AWS_ACCESS_KEY_ID,
 secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
 },
});

async function sendEmail(to, subject, text) {
 const transporter = nodemailer.createTransport({
 SES: { ses, aws: { region: process.env.AWS_REGION } },
 });

 const mailOptions = {
 from: '[email protected]',
 to,
 subject,
 text,
 };

 try {
 const result = await transporter.sendMail(mailOptions);
 console.log('Email sent:', result);
 } catch (error) {
 console.error('Error sending email:', error);
 }
}

const main = async () => {
 await sendEmail('[email protected]', 'Test Subject', 'Hello from AWS SES!');
};

main();

What’s Next?

Once you’ve got email sending working, look into setting up a templating engine for your emails, like Handlebars or EJS. This allows for more dynamic email content, which is essential for marketing and user engagement.

FAQ

  1. How do I verify an email address in SES?
    Log into the AWS console, navigate to SES, and find the “Email Addresses” section. Enter the email you want to verify and follow the instructions.
  2. Can I send bulk emails with Amazon SES?
    Yes, but you need to handle batching yourself. Amazon SES allows you to send emails to multiple recipients in one send operation, but you must be careful with the daily sending limits.
  3. Are there any costs associated with using Amazon SES?
    Amazon SES is relatively cheap. You pay for the emails you send, but if you’re sending from an Amazon EC2 instance, the first 62,000 emails are free.

Data Sources

Last updated May 12, 2026. Data sourced from official docs and community benchmarks.

🕒 Published:

✍️
Written by Jake Chen

AI technology writer and researcher.

Learn more →
Browse Topics: Best Practices | Case Studies | General | minimalism | philosophy
Scroll to Top