How to use Java to send SMTP emails with Amazon Simple Email Service (SES)

So you want to programmatically send emails with Amazon Simple Email Service, or SES for short.
This article concerns how to do exactly that in Java.
What is Amazon Simple Email Service?
According to Amazon, “Amazon Simple Email Service (SES) is a cost-effective, flexible, and scalable email service that enables developers to send mail from within any application. You can configure Amazon SES quickly to support several email use cases, including transactional, marketing, or mass email communications. Amazon SES’s flexible IP deployment and email authentication options help drive higher deliverability and protect sender reputation, while sending analytics measure the impact of each email. With Amazon SES, you can send email securely, globally, and at scale.”
The use cases range from transactional ones (like sending password re-set emails, purchase confirmations, and more) to marketing emails (like special offers, coupons, newsletters, and more) to bulk email communication (like notifications, announcements, and more).
The customers of Amazon SES range from Reddit to Netflix to Duolingo, so you know you’re using an email solution that’s good enough for the biggest players in the game.
First, let’s do some set-up
Before we get to coding, you’ll have to log into your AWS Management Console. Here’s a link for you to get there if you don’t already have it bookmarked.
Then, type in SES
in the search bar and then click on it in order to go to the SES Console specifically.
Verify the emails you’ll be sending to and from
On the left-hand toolbar, click on Email Addresses
under the Identity Management
section.
There will be a button that says Verify a New Email Address
. Click on it, and a modal will display.

Fill in the text input with the email you want to verify; remember, you’ll have to do this not only for the email(s) you wish to send from, but also the email(s) you wish to send to!
Then, you’ll want to access the e-mail(s) you enter and then follow the confirmation instructions inside the messages to verify the e-mail address(es).
Get your SES SMTP Credentials
If you’re still in the AWS Management Console and still in the SES
section, then stay there. If not, then navigate there.
Once there, choose SMTP Settings
. Then, select Create My SMTP Credentials
. Fill out the field for the IAM User Name:

Then, click on Show User SMTP Credentials
. Copy and paste your credentials somewhere safe, because once you exit out of this window, you won’t be able to view or save them again.
For more information on this step, check out the AWS Docs on this subject.
The Java code
Now that you’ve verified the e-mail address(es), you can now move onto coding.
Note the SMTP endpoint address. In the example above, I put "email-smtp.us-west-1.amazonaws.com
. This could be yours as well, but you’ll have to find your exact address according to your particular API endpoint depending on your AWS region. This AWS doc describes this point a little more.
Assuming you have the correct SMTP endpoint address, verified e-mail address(es), and haven’t exceeded any sending quotas (which starts at 200 messages over a 24-hour period in AWS sandbox accounts), then the above code should be fairly plug-and-play.
I hope that now you have enough information to not only get started with sending e-mails with Amazon Simple Email Service (SES) but also have the code to do so. If you have any questions, then don’t hesitate to reach out in the comment section.