Amazon SES sendEmail example

public class AWSeMailService {

 public static void send(AmazonSimpleEmailService ses, String from,
   String to, String subject, String body) throws IOException {

   * Before you can send email via Amazon SES, you need to verify that you
   * own the email address from which you'll be sending email. This will
   * trigger a verification email, which will contain a link that you can
   * click on to complete the verification process.
  verifyEmailAddress(ses, from);
   // RETERN_PATH is optional

  SendEmailRequest sendEmailRequest = new SendEmailRequest()

  List toAddresses = new ArrayList<>();

  Destination destination = new Destination()

  sendEmailRequest.setDestination(destination); message

  = new Content()
    .withCharset("UTF-8").withData(subject + ""), new Body(
    new Content().withCharset("UTF-8").withData(body)));



  * Important: Be sure to fill in an email address you have access to so that
  * you can receive the initial confirmation email from Amazon Simple Email
  * Service.
 private static final String RETERN_PATH = "";
 private static final String TO = "";
 private static final String FROM = "";
 private static final String BODY = "This is an email by java from Amazon Simple Email Service!";
 private static final String SUBJECT = "A trying mail from Amazon SES by Java";

 public static void main(String[] args) throws IOException {
   * Important: Be sure to fill in your AWS access credentials in the
   * file before you try to run this sample.
  PropertiesCredentials credentials = new PropertiesCredentials(
  AmazonSimpleEmailService ses = new AmazonSimpleEmailServiceClient(

  AWSeMailService.send(ses, FROM, TO, SUBJECT, BODY);


  * Sends a request to Amazon Simple Email Service to verify the specified
  * email address. This triggers a verification email, which will contain a
  * link that you can click on to complete the verification process.
  * @param ses
  *            The Amazon Simple Email Service client to use when making
  *            requests to Amazon SES.
  * @param address
  *            The email address to verify.
 private static void verifyEmailAddress(AmazonSimpleEmailService ses,
   String address) {

  String domain = address.substring(address.indexOf("@") + 1);

  List lids = ses.listIdentities().getIdentities();

  if (lids.contains(address) || lids.contains(domain)) {

  ses.verifyEmailAddress(new VerifyEmailAddressRequest()
  System.out.println("Please check the email address " + address
    + " to verify it");

Popular posts from this blog

How to get Active Transactions and Locks from MySQL

Example of a PAC file