Send an email using the AWS SDK for Java - Amazon Simple Email Service Classic

This is the user guide for Amazon SES Classic. Updates and new features are only being documented in the new Amazon SES Developer Guide which we recommend to use.

Send an email using the AWS SDK for Java

The following procedure shows you how to use Eclipse IDE for Java EE Developers and AWS Toolkit for Eclipse to create an AWS SDK project and modify the Java code to send an email through Amazon SES.


In this getting started tutorial, you send an email to yourself so that you can check to see if you received it. For further experimentation or load testing, use the Amazon SES mailbox simulator. Emails that you send to the mailbox simulator do not count toward your sending quota or your bounce and complaint rates. For more information, see Testing email sending in Amazon SES.


Before you begin, perform the following tasks:

  • Verify your email address with Amazon SES—Before you can send an email with Amazon SES, you must verify that you own the sender's email address. If your account is still in the Amazon SES sandbox, you must also verify the recipient email address. The easiest way to verify email addresses is by using the Amazon SES console. For more information, see Verifying email addresses in Amazon SES.

  • Get your AWS credentials—You need an AWS access key ID and AWS secret access key to access Amazon SES using an SDK. You can find your credentials by using the Security Credentials page in the AWS Management Console. For more information about credentials, see Types of Amazon SES credentials.

  • Install Eclipse—Eclipse is available at The code in this tutorial was tested using Eclipse Neon.3 (version 4.6.3), running version 1.8 of the Java Runtime Environment.

  • Install the AWS Toolkit for Eclipse—Instructions for adding the AWS Toolkit for Eclipse to your Eclipse installation are available at The code in this tutorial was tested using version 2.3.1 of the AWS Toolkit for Eclipse.

  • Create a shared credentials file—For the sample code in this section to function properly, you must create a shared credentials file. For more information, see Create a shared credentials file.


The following procedure shows how to send an email through Amazon SES using the AWS SDK for Java.

To send an email using the AWS SDK for Java

  1. Create an AWS Java Project in Eclipse by performing the following steps:

    1. Start Eclipse.

    2. On the File menu, choose New, and then choose Other. On the New window, expand the AWS folder, and then choose AWS Java Project.

    3. In the New AWS Java Project dialog box, do the following:

      1. For Project name, type a project name.

      2. Under AWS SDK for Java Samples, select Amazon Simple Email Service JavaMail Sample.

      3. Choose Finish.

  2. In Eclipse, in the Package Explorer pane, expand your project.

  3. Under your project, expand the src/main/java folder, expand the folder, and then double-click

  4. Replace the entire contents of with the following code:

    package com.amazonaws.samples; import; import com.amazonaws.regions.Regions; import; import; import; import; import; import; import; public class AmazonSESSample { // Replace with your "From" address. // This address must be verified with Amazon SES. static final String FROM = ""; // Replace with a "To" address. If your account // is still in the sandbox, this address must be verified. static final String TO = ""; // The configuration set to use for this email. If you do not want to use a // configuration set, comment the following variable and the // .withConfigurationSetName(CONFIGSET); argument below. static final String CONFIGSET = "ConfigSet"; // The subject line for the email. static final String SUBJECT = "Amazon SES test (AWS SDK for Java)"; // The HTML body for the email. static final String HTMLBODY = "<h1>Amazon SES test (AWS SDK for Java)</h1>" + "<p>This email was sent with <a href=''>" + "Amazon SES</a> using the <a href=''>" + "AWS SDK for Java</a>"; // The email body for recipients with non-HTML email clients. static final String TEXTBODY = "This email was sent through Amazon SES " + "using the AWS SDK for Java."; public static void main(String[] args) throws IOException { try { AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.standard() // Replace US_WEST_2 with the AWS Region you're using for // Amazon SES. .withRegion(Regions.US_WEST_2).build(); SendEmailRequest request = new SendEmailRequest() .withDestination( new Destination().withToAddresses(TO)) .withMessage(new Message() .withBody(new Body() .withHtml(new Content() .withCharset("UTF-8").withData(HTMLBODY)) .withText(new Content() .withCharset("UTF-8").withData(TEXTBODY))) .withSubject(new Content() .withCharset("UTF-8").withData(SUBJECT))) .withSource(FROM) // Comment or remove the next line if you are not using a // configuration set .withConfigurationSetName(CONFIGSET); client.sendEmail(request); System.out.println("Email sent!"); } catch (Exception ex) { System.out.println("The email was not sent. Error message: " + ex.getMessage()); } } }
  5. In, replace the following with your own values:


    The email addresses are case-sensitive. Make sure that the addresses are exactly the same as the ones you verified.

    • SENDER@EXAMPLE.COM—Replace with your "From" email address. You must verify this address before you run this program. For more information, see Verifying identities in Amazon SES.

    • RECIPIENT@EXAMPLE.COM—Replace with your "To" email address. If your account is still in the sandbox, you must verify this address before you use it. For more information, see Moving out of the Amazon SES sandbox.

    • (Optional) us-west-2—If you want to use Amazon SES in a region other than US West (Oregon), replace this with the region you want to use. For a list of regions where Amazon SES is available, see Amazon Simple Email Service (Amazon SES) in the AWS General Reference.

  6. Save

  7. To build the project, choose Project and then choose Build Project.


    If this option is disabled, automatic building may be enabled; if so, skip this step.

  8. To start the program and send the email, choose Run and then choose Run again.

  9. Review the output of the console pane in Eclipse. If the email was successfully sent, the console displays "Email sent!" Otherwise, it displays an error message.

  10. If the email was successfully sent, sign in to the email client of the recipient address. You will find the message that you sent.