Using Amazon Simple Email Service (SES) to Send Single Emails
by Kurt Feeley

Photo by Valeria Reverdo on Unsplash
This article is part of a series to introduce developers to Amazon Simple Email Service. Check out all the articles.
Introduction to Amazon Simple Email Service – SES
Using the CLI to Set Up Amazon SES Email Identities and Contact Lists.
Using Amazon Simple Email Service (SES) to Send Single Emails
Using Amazon Simple Email Service (SES) to Send Bulk, Templated Emails
The Solution
In this tutorial, we’ll demonstrate how to use Amazon SES to send single emails, like an account confirmation email, password reset email, or an online order invoice email.
Remember, for any example solution from AWS with .NET, we focus on the code that exemplifies the problem we are trying to solve. We don’t include logging, input validation, exception handling, etc., and we sometimes embed the configuration data within classes instead of using environment variables, configuration files, key/value stores, and the like. These items should not be skipped for proper solutions.
Prerequisites
To complete this solution, you will need the .NET CLI which is included in the .NET SDK. In addition, you will need to create an AWS IAM user with programmatic access with the appropriate permissions to interact with Amazon Simple Email Service. You will also need to download the AWS CLI and configure your environment.
If you have not already, complete the first step and setup Amazon SES email identities and contact lists before you complete this tutorial.
Warning: Some AWS services may incur fees.
Our Dev Environment
This tutorial was developed using Ubuntu 24.04.3, .NET 8 SDK and Visual Studio Code 1.108.1. Some commands/constructs may vary across systems.
Create the .NET Amazon SES Application Project
If you would like to use the code in this article in a .NET App, you will need to create a .NET app project like the following. In this example, we name the application SimpleEmailSender.
$ dotnet new console -n SimpleEmailSender
Add Nuget Package Dependencies
With the app created, we’ll now add the AWS .NET SDK dependencies.
For this article, we will only need to add one nuget package, which is the Amazon SES v2 SDK.
$ dotnet add package AWSSDK.SimpleEmailV2
The EmailService Class
We’ll now encapsulate our interactions with Amazon SES in an Email Service Class, which we will call EmailService.
So, the first step is to create that class to encapsulate the Amazon Simple Email Service SDK usage.
public class EmailService
{
}
We’ll now build out this class a bit. The first things we will add are the using statements to wire up our dependencies.
using Amazon.SimpleEmailV2;
using Amazon.SimpleEmailV2.Model;
Next, we create a field named _fromEmailAddress, to hold the email address that we will be sending email from. We’ll also create a field to hold an instance of the Amazon SES client, _sesClient, that we will use throughout the class.
We’ll finish by initializing _fromEmailAddress and instantiating the SES client in the class constructor.
private readonly IAmazonSimpleEmailServiceV2 _sesClient;
private readonly string _fromEmailAddress;
public EmailService(string fromEmailAddress)
{
_fromEmailAddress = fromEmailAddress;
_sesClient = new AmazonSimpleEmailServiceV2Client();
}
For this use case, we will create one method, SendSingleEmail.
Using Amazon Simple Email Service (SES) to Send Single Emails
For this use case, we will simply send one email to one recipient. Sending single emails from your application could be to satisfy requirements for sending an invoice after a purchase, sending an email to reset a password or sending an email for account verification.
The method, “SendSingleEmailAsync”, will send an email to one address with both HTML and Text content being passed into the method. For this method, we will not only pass in parameters for the HTML and Text content, but also the recipient email, and the email subject.
public async Task<string> SendSingleEmailAsync(
string recipientEmail,
string subject,
string htmlContent,
string textContent)
{
}
The first thing that we will do is create a SendEmailRequest. When creating the SendEmailRequest, we will reference the recipientAddress parameter in the Desination as a value for ToAddresses. We will also set the HTML and Text content as well as the subject within the EmailContent object.
var sendEmailRequest = new SendEmailRequest
{
FromEmailAddress = _fromEmailAddress,
Destination = new Destination
{
ToAddresses = new List<string> { recipientEmail }
},
Content = new EmailContent
{
Simple = new Message
{
Subject = new Content
{
Data = subject,
Charset = "UTF-8"
},
Body = new Body
{
Html = new Content
{
Charset = "UTF-8",
Data = htmlContent
},
Text = new Content
{
Charset = "UTF-8",
Data = textContent
}
}
}
}
};
Once the SendEmailRequest object is instantiated, using our Amazon SES Client, we’ll send the request to Amazon SES and wait for the response.
Finally, we will return the Amazon SES message id.
SendEmailResponse response = await _sesClient.SendEmailAsync(sendEmailRequest);
return response.MessageId;
Here’s the completed SendSingleEmailAsync method.
public async Task<string> SendSingleEmailAsync(
string recipientEmail,
string subject,
string htmlContent,
string textContent)
{
try
{
var sendEmailRequest = new SendEmailRequest
{
FromEmailAddress = _fromEmailAddress,
Destination = new Destination
{
ToAddresses = new List<string> { recipientEmail }
},
Content = new EmailContent
{
Simple = new Message
{
Subject = new Content
{
Data = subject,
Charset = "UTF-8"
},
Body = new Body
{
Html = new Content
{
Charset = "UTF-8",
Data = htmlContent
},
Text = new Content
{
Charset = "UTF-8",
Data = textContent
}
}
}
}
};
SendEmailResponse response = await _sesClient.SendEmailAsync(sendEmailRequest);
return response.MessageId;
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
return "Error";
}
}
Implementing the EmailService
Implementing the SendSingleEmailAsync method in the EmailService class is simple.
Below are all the parts you would expect in order to send the email. We’ll first set the sender’s email address and the recipient’s email address along with the email subject.
The last part is to provide the content of the email. In this example we are also providing content in both text and HTML format.
var senderEmailAddress = "some.name@emaildomain.example";
var recipientEmailAddress = "fakeemailuser@emailtodomain.email";
var emailSubject = "Account Verification";
var textContent = @"
Please verify your account by visiting the following link:
http://fakeexampleverification.url";
var htmlContent = @"
<html>
<body>
<p>Please verify your account by clicking the following link:</p>
<p>
<a href='http://fakeexampleverification.url'>
Verify Account
</a>
</p>
</body>
</html>";
With everything set to send the email – we’ll now instantiate the EmailService, passing in the senderEmailAddress in the class constructor. Once the EmailService class is instantiated, we can now call SendSingleEmailAsync, passing in the recipient email, the email subject and both the HTML and text content.
EmailService emailService = new EmailService(senderEmailAddress);
string messageId = await emailService.SendSingleEmailAsync(
recipientEmailAddress,
emailSubject,
htmlContent,
textContent);
What’s Next?
Move over to the next article in this series to extend the EmailService class to send bulk, templated emails.
Summary
We have concluded this article where you have learned how to:
- Create a .NET app using the .NET CLI.
- Add Nuget packages to a .NET app using the .NET CLI.
- Send a Single email using the AWS .NET SES SDK.
Want to know more about the tech in this article? Check out these resources: