Quick start on sending email with Amazon SES on Node.js

Although Amazon provides great documentation, this is what all I needed to send an email with Amazon SES (Simple Email Service) on Node.js.

Get Started with Amazon SES

To start, visit Amazon SES and hit Get started with Amazon SES. Then Amazon asks which region you want to use SES. Note that region for SES doesn’t need to be the same with your other Amazon services.

Verify Your Domain or Email Address

After choosing the region, you will see the page above. I highlighted menus you need. You can use two types of identities, domains and email addresses. If you have your own domain and you want to send an email from the domain, the first one needs to be configured. If you want to send an email from your existing email account such as Gmail and Outlook, the second one needs to be configured. The first one and the second one is not mutually exclusive. You can use both.

Option 1: Verify Your Domain

After entering Domains menu, hit Verify a New Domain.

In the popup, type your domain in interest, check Generate DKIM Settings and hit Verify This Domain.

For a given domain, SES requests you to configure DNS records in order to verify whether the domain is owned by you. SES will try to verify the domain constantly. If verification succeeds, you will see Verification: verified, DKIM Status: verified, Enalbed for: Yes in the dashboard as shows in the above. Then it’s all set.

Option 2: Verify Your Email Address

Verifying an email address is simpler. After entereing Email Addresses menu, hit Verify a New Email Address and type an email address in interest. And then SES will send a verification email to a given email address. Once you visit a link given in the verification email, the email address will be verified. Then it’s all set.

Build Node.js Application Sending Email with SES

Install AWS SDK

1
$ npm install aws-sdk

Configure AWS Credentials

To verify whether your Node.js application has the right permissions to send an email with SES, you need to provide the right credentials to AWS SDK.

Visit IAM Management Console and hit Create New Access Key.

Don’t worry. The keys have been deleted

Remember the created access key and write it down to the following file:

  • Windows: C:\Users\*USERNAME*\.aws\credentials
  • Linux, Unix, or macOS: ~/.aws/credentials
1
2
3
[default]
aws_access_key_id = AKIAJ4LGGMQNZ4IJK5XA
aws_secret_access_key = 00pkJqVkmR70kLpXRoqRaoB6zcpo1OmnVeuKvlyP

Now AWS SDK will read access key from the credential file and prove your application has the right permissions.

Also you can store AWS credentials in JSON file and load it from Node.js.

Note: Access key allows full access to your Amazon AWS. Do not disclose access key publicly. I recommend to create an IAM user and allows only SES

Script Sending Email with SES

The simplest Node.js script sending an email with SES is provided in Amazon Documentation or its GitHub repository, so I’ll skip the entire script here:

Requst a Sending Limit Increase

Initially, your SES operates in sandbox mode andcan send an email only to domains or email addresses which you verified in the above. To be able to send an email to anyone, you need to Request a Sending Limit Increase.

Visit Create Case and create a case to request a sending limit increase.