SDKs overview
Amazon Simple Email Service (SES) provides several methods for programmatic access, primarily through its official Software Development Kits (SDKs) and a growing ecosystem of community-contributed libraries. The official AWS SDKs are designed to simplify interaction with AWS services, including SES, by handling details such as request signing, retries, and error handling. These SDKs are available across multiple programming languages, enabling developers to integrate email sending and receiving capabilities directly into their applications.
The SDKs abstract the underlying REST API calls, allowing developers to interact with SES using native language constructs. This facilitates tasks such as sending transactional emails, managing email templates, verifying sender identities, and monitoring sending activity. While the official SDKs cover the full range of SES functionalities, community libraries often provide higher-level abstractions, specialized functionalities, or integrations with specific frameworks. Developers can choose the most suitable tool based on their project's language, framework, and specific requirements for interacting with Amazon SES.
Official SDKs by language
Amazon SES is accessible through the AWS SDKs, which are maintained by Amazon Web Services. These SDKs are designed to provide consistent, idiomatic interfaces for various programming languages, enabling developers to interact with the full range of SES features. The SDKs manage authentication, serialization, and network communication, allowing developers to focus on application logic. Each SDK typically includes client classes, data models for requests and responses, and utility functions specific to the AWS ecosystem.
The following table outlines the official AWS SDKs that support Amazon SES, along with their respective package names, installation commands, and general maturity levels. These SDKs are regularly updated to support new SES features and maintain compatibility with the latest language versions and AWS API specifications.
| Language | Package / Module | Install Command | Maturity |
|---|---|---|---|
| JavaScript | @aws-sdk/client-ses |
npm install @aws-sdk/client-ses or yarn add @aws-sdk/client-ses |
Stable (v3) |
| Python | boto3 |
pip install boto3 |
Stable |
| Java | aws-java-sdk-ses (v1) / software.amazon.awssdk:ses (v2) |
Maven: <dependency><groupId>software.amazon.awssdk</groupId><artifactId>ses</artifactId><version>2.x.x</version></dependency> |
Stable (v2 recommended) |
| Ruby | aws-sdk-ses |
gem install aws-sdk-ses |
Stable (v3) |
| Go | github.com/aws/aws-sdk-go-v2/service/ses |
go get github.com/aws/aws-sdk-go-v2/service/ses |
Stable (v2) |
| PHP | aws/aws-sdk-php |
composer require aws/aws-sdk-php |
Stable (v3) |
| .NET | AWSSDK.SimpleEmailV2 |
Install-Package AWSSDK.SimpleEmailV2 (NuGet) |
Stable |
| C++ | aws-sdk-cpp (SES client) |
Building from source or package manager (details vary by platform) | Stable |
For detailed documentation and specific usage examples for each language, refer to the official AWS SDK documentation portal.
Installation
The installation process for AWS SDKs is generally standardized across languages, typically involving package managers. Before installation, ensure you have the appropriate language runtime and package manager set up in your development environment. You will also need AWS credentials configured, either via environment variables, a shared credentials file (~/.aws/credentials), or an IAM role, for the SDKs to authenticate with SES.
Python (boto3)
Install the boto3 library using pip, Python's package installer:
pip install boto3
This command installs the full boto3 library, which includes support for all AWS services, including SES. For more specific installation options, consult the boto3 documentation.
JavaScript (AWS SDK for JavaScript v3)
Install the specific SES client module using npm or Yarn:
npm install @aws-sdk/client-ses
# or
yarn add @aws-sdk/client-ses
The AWS SDK for JavaScript v3 adopts a modular approach, allowing you to install only the service clients you need, reducing bundle size. For comprehensive installation instructions and configuration, see the AWS SDK for JavaScript v3 Developer Guide.
Java (AWS SDK for Java v2)
For Maven projects, add the following dependency to your pom.xml file:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>ses</artifactId>
<version>2.x.x</version> <!-- Replace with the latest version -->
</dependency>
For Gradle projects, add the following to your build.gradle file:
implementation 'software.amazon.awssdk:ses:2.x.x' // Replace with the latest version
The AWS SDK for Java v2 offers a non-blocking I/O client and improved performance. Refer to the AWS SDK for Java Developer Guide for detailed setup instructions.
Quickstart example
This quickstart example demonstrates how to send a basic email using Amazon SES with the Python boto3 SDK. Before running this code, ensure you have boto3 installed and your AWS credentials configured, with permissions to send email via SES.
The example sends a plain text email. For HTML emails or attachments, additional parameters and MIME type handling would be required, as detailed in the Amazon SES Developer Guide for Python.
import boto3
from botocore.exceptions import ClientError
# Replace with your SES verified sender email address
SENDER = "Sender Name <[email protected]>"
# Replace with the recipient's email address
RECIPIENT = "[email protected]"
# The AWS region to use for SES (e.g., 'us-east-1')
AWS_REGION = "us-east-1"
# The subject line for the email
SUBJECT = "Amazon SES Test Email (boto3)"
# The character encoding for the email
CHARSET = "UTF-8"
# The email body for recipients with non-HTML email clients
BODY_TEXT = ("Amazon SES Test Email from Python.\r\n"
"This email was sent with Amazon SES using the AWS SDK for Python (boto3).")
# Create a new SES client
client = boto3.client('ses', region_name=AWS_REGION)
try:
# Provide the contents of the email.
response = client.send_email(
Destination={
'ToAddresses': [
RECIPIENT,
],
},
Message={
'Body': {
'Text': {
'Charset': CHARSET,
'Data': BODY_TEXT,
},
},
'Subject': {
'Charset': CHARSET,
'Data': SUBJECT,
},
},
Source=SENDER,
)
print(f"Email sent! Message ID: {response['MessageId']}")
except ClientError as e:
print(f"Error sending email: {e.response['Error']['Message']}")
To execute this example:
- Replace
SENDERwith an Amazon SES verified email address or domain. - Replace
RECIPIENTwith the email address you wish to send to. - Update
AWS_REGIONif your SES setup is in a different AWS region. - Save the code as a
.pyfile (e.g.,send_ses_email.py). - Run it from your terminal:
python send_ses_email.py.
A successful execution will print the Message ID returned by SES, confirming the email has been queued for delivery. Error messages will provide details if the send operation fails.
Community libraries
Beyond the official AWS SDKs, the developer community has created various libraries and wrappers that can simplify working with Amazon SES, often providing higher-level abstractions, framework integrations, or specialized features. While these libraries are not officially supported by AWS, they can offer convenience and tailored solutions for specific use cases. Before adopting a community library, it is advisable to check its maintenance status, documentation, and community support.
Django-SES (Python)
django-ses is a popular Django email backend that allows Django applications to send email using Amazon SES. It integrates seamlessly with Django's email system, making it a drop-in replacement for other email backends. It supports features like attachment handling, HTML emails, and custom headers. Its primary benefit is simplifying the configuration of SES within a Django project, abstracting away the direct boto3 calls for email sending.
Installation:
pip install django-ses
Configuration in Django settings:
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_SES_REGION_NAME = 'us-east-1'
AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
# AWS_SES_ACCESS_KEY_ID and AWS_SES_SECRET_ACCESS_KEY can be set here or via environment variables
For more details, refer to the django-ses GitHub repository.
Laravel SES Driver (PHP)
For PHP applications built with the Laravel framework, a common approach is to use the official AWS SDK for PHP directly or leverage community packages that provide a more Laravel-idiomatic integration. Laravel's built-in mailer supports various drivers, and the AWS SDK can be configured as a custom driver. Packages like aws/aws-sdk-php-laravel (though often integrated directly via the main SDK now) simplify the process of setting up SES as the mail driver for Laravel applications, allowing developers to use Laravel's familiar Mail facade.
Installation of AWS SDK for PHP (required for Laravel integration):
composer require aws/aws-sdk-php
Configuration in Laravel's config/mail.php:
'ses' => [
'driver' => 'ses',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
More information on integrating SES with Laravel can be found in the Laravel Mail documentation.
Nodemailer with AWS SES Transport (JavaScript/Node.js)
Nodemailer is a well-known module for Node.js applications to send emails. It supports various transports, including an AWS SES transport, which allows it to send emails through Amazon SES using the AWS SDK for JavaScript. This combination provides a flexible way to compose and send emails in Node.js, leveraging Nodemailer's rich features for email content and attachments, while relying on SES for reliable delivery.
Installation:
npm install nodemailer @aws-sdk/client-ses
Example usage:
import { SESClient, SendRawEmailCommand } from "@aws-sdk/client-ses";
import nodemailer from "nodemailer";
const ses = new SESClient({ region: "us-east-1" });
const transporter = nodemailer.createTransport({
SES: {
ses,
aws: { Ses: SendRawEmailCommand },
},
});
async function sendEmail() {
try {
const info = await transporter.sendMail({
from: "[email protected]",
to: "[email protected]",
subject: "Nodemailer SES Test",
text: "Hello from Nodemailer via SES!",
html: "<b>Hello from Nodemailer via SES!</b>",
});
console.log("Message sent: %s", info.messageId);
} catch (error) {
console.error("Error sending email:", error);
}
}
sendEmail();
Further documentation on Nodemailer and its SES transport can be found on the Nodemailer SES transport guide.
When selecting a community library, consider factors such as active development, compatibility with current AWS SDK versions, and alignment with your project's architectural patterns. These libraries can significantly reduce development effort for common tasks but may introduce an additional layer of abstraction to manage.