In this article, we’ll build a simple program to send a simple email using Simple Email Service (SES).
This article is part of the ‘AWS Simple Email Service‘ series here at CloudTechPro.
2. Configuring Email Addresses
2.1. Verifying Email Addresses
First of all, we need a verified email address. We’ll use this address for sending and receiving email.
If you don’t have verified email, check out AWS’s documentation for verifying email address in SES.
2.2. Configuring Email Address
To run the sample program, you need to replace sample email from your own verified email. Let’s replace the following email from the sample program. You are free to use the same email in both fields.
private static String senderEmail = "email@example.com"; private static String contact = "firstname.lastname@example.org";
Now, this email will be used as a sender and receiver.
3. Configuring Email
First, we need a destination where we send the email. Let’s configure a destination.
Destination destination = new Destination(); List<String> toAddresses = new ArrayList<String>(); toAddresses.add("email@example.com"); destination.setToAddresses(toAddresses);
Second, we need a to prepare message. Let’s create an email body.
Body body = new Body(); body.setText(new Content(emailText)); Message message = new Message(); message.setSubject(new Content(subject)); message.setBody(body);
We’ve set a plain text in the email body. If you want to include HTML content, just use setHtml method under Body class.
4. Sending Email
Now, it’s time to check by sending an email. Let’s prepare a request.
SendEmailRequest sendEmailRequest = new SendEmailRequest(); sendEmailRequest.withSource(senderEmail); sendEmailRequest.withDestination(destination); sendEmailRequest.withMessage(message); SendEmailResult emailResult = ses.sendEmail(sendEmailRequest);
Now we are ready to send this request. Let’s execute this program and you will receive a message ID in response.
In this article, we’ve seen how to send a simple email using Simple Email Service (SES).
As always, sample program can be found over on GitHub.