List of usage examples for com.amazonaws.services.simpleemail.model Destination Destination
public Destination()
From source file:AmazonSESSample.java
License:Open Source License
public static void main(String[] args) throws IOException { // Construct an object to contain the recipient address. Destination destination = new Destination().withToAddresses(new String[] { TO }); // Create the subject and body of the message. Content subject = new Content().withData(SUBJECT); Content textBody = new Content().withData(BODY); Body body = new Body().withText(textBody); // Create a message with the specified subject and body. Message message = new Message().withSubject(subject).withBody(body); // Assemble the email. SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination) .withMessage(message);/*from w w w . j a v a 2 s . c om*/ try { System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java..."); /* * The ProfileCredentialsProvider will return your [haow2] * credential profile by reading from the credentials file located at * (/Users/Dawn/.aws/credentials). * * TransferManager manages a pool of threads, so we create a * single instance and share it throughout our application. */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("haow2").getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (/Users/Dawn/.aws/credentials), and is in valid format.", e); } // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials. AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials); // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production // access status, sending limits, and Amazon SES identity-related settings are specific to a given // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are US_WEST_2 // and EU_WEST_1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Region REGION = Region.getRegion(Regions.US_EAST_1); client.setRegion(REGION); // Send the email. client.sendEmail(request); System.out.println("Email sent!"); } catch (Exception ex) { System.out.println("The email was not sent."); System.out.println("Error message: " + ex.getMessage()); } }
From source file:com.adeptj.modules.aws.ses.internal.AwsSesService.java
License:Apache License
/** * {@inheritDoc}// www.j a va2 s. c o m */ @Override public EmailResponse sendEmail(EmailRequest emailRequest) { try { SendEmailResult result = this.asyncSES .sendEmail(new SendEmailRequest().withSource(this.emailConfig.from()) .withDestination(new Destination().withToAddresses(emailRequest.getRecipientToList()) .withCcAddresses(emailRequest.getRecipientCcList()) .withBccAddresses(emailRequest.getRecipientBccList())) .withMessage(new Message() .withSubject(new Content().withData(emailRequest.getSubject())).withBody( new Body().withHtml(new Content().withData(emailRequest.getBody()))))); return new EmailResponse(result.getMessageId(), result.getSdkHttpMetadata().getHttpStatusCode(), result.getSdkHttpMetadata().getHttpHeaders()); } catch (Exception ex) { LOGGER.error("Exception while sending email!!", ex); throw new AwsException(ex.getMessage(), ex); } }
From source file:com.adeptj.modules.aws.ses.internal.AwsSesService.java
License:Apache License
/** * {@inheritDoc}/*w w w. ja v a 2 s. c o m*/ */ @Override public void sendEmailAsync(EmailRequest emailRequest) { try { // Shall we use the Future object returned by async call? this.asyncSES.sendEmailAsync( new SendEmailRequest().withSource(this.emailConfig.from()) .withDestination(new Destination().withToAddresses(emailRequest.getRecipientToList()) .withCcAddresses(emailRequest.getRecipientCcList()) .withBccAddresses(emailRequest.getRecipientBccList())) .withMessage( new Message().withSubject(new Content().withData(emailRequest.getSubject())) .withBody(new Body() .withHtml(new Content().withData(emailRequest.getBody())))), this.asyncHandler); } catch (Exception ex) { LOGGER.error("Exception while sending email asynchronously!!", ex); } }
From source file:com.amazon.aws.demo.SESManager.java
License:Open Source License
/** Send the feedback message based on data entered */ public static boolean sendFeedbackEmail(String comments, String name, float rating) { String subjectText = "Feedback from " + name; Content subjectContent = new Content(subjectText); String bodyText = "Rating: " + rating + "\nComments\n" + comments; Body messageBody = new Body(new Content(bodyText)); Message feedbackMessage = new Message(subjectContent, messageBody); String email = PropertyLoader.getInstance().getVerifiedEmail(); Destination destination = new Destination().withToAddresses(email); SendEmailRequest request = new SendEmailRequest(email, destination, feedbackMessage); try {// w w w .j a va2s. c o m SendEmailResult result = FeedbackFormDemoActivity.clientManager.ses().sendEmail(request); } catch (Throwable e) { Log.e(LOG_TAG, "Error sending mail" + e); return false; } return true; }
From source file:com.app.ses.AmazonSES.java
License:Open Source License
public void sendMail(String TO, String USUARIO2, String SUBJECT, String CONTENIDO, String FOLIO, String USERCREATE, String NOMBRE) { // Construct an object to contain the recipient address. Destination destination = new Destination().withToAddresses(new String[] { TO }); // Create the subject and body of the message. Content subject = new Content().withData(SUBJECT); Content htmlContent = new Content().withData(" <body bgcolor=\"#FFFFFF\">\n" + " <!-- HEADER -->\n" + " <table class=\"head-wrap\" bgcolor=\"red\">\n" + " <tr>\n" + " <td></td>\n" + " <td class=\"header container\" >\n" + " <div class=\"content\">\n" + " <table bgcolor=\"red\">\n" + " <tr>\n" + " <td style=\"font-size: x-large; color:white;\">\n" + " S G C o n\n" + " </td>\n" + " <td style=\"text-align: right; color:white; fon\">\n" + " Notificaciones\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " </div>\n" + " </td>\n" + " <td></td>\n" + " </tr>\n" + " </table><!-- /HEADER -->\n" + " <!-- BODY -->\n" + " <table class=\"body-wrap\">\n" + " <tr>\n" + " <td></td>\n" + " <td class=\"container\" bgcolor=\"#FFFFFF\">\n" + " <div class=\"content\">\n" + " <table>\n" + " <tr>\n" + " <td>\n" + " <h3>Hola, " + USUARIO2 + "</h3>\n" + " <p class=\"callout\">\n" + " " + CONTENIDO + "\n" + " </p>\n" + " <p>\n" + " <table style=\"font-size: medium\">\n" + " <tr>\n" + " <td>Folio: " + FOLIO + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td>" + USERCREATE + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td>" + NOMBRE + "</td>\n" + " </tr>\n" + " </table>\n" + " </p> <br/>\n" + " <table>\n" + " <tr>\n" + " <td>\n" + " <p>\n" + " <a href=\"http://www.sgcon-infonavit.com\" class=\"soc-btn fb\">Ir a la aplicacin</a> \n" + " </p>\n" + " </td>\n" + " </tr>\n" + " </table\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " </div>\n" + " </td>\n" + " <td></td>\n" + " </tr>\n" + " </table>\n" + " </body>"); Body body = new Body().withHtml(htmlContent); // Create a message with the specified subject and body. Message message = new Message().withSubject(subject).withBody(body); // Assemble the email. SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination) .withMessage(message);/*from ww w. j a va2 s . co m*/ try { System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java..."); /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). * * TransferManager manages a pool of threads, so we create a * single instance and share it throughout our application. */ /*AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException( "Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); }*/ AWSCredentials awsCreds = new BasicAWSCredentials("AKIAJFO4NNHIPNTB4ZCQ", "VjYeQ9+xj3HAcLBSxxxbHTo6jy2ft0wF6tgWZXmA"); // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials. //AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials); AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(awsCreds); // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production // access status, sending limits, and Amazon SES identity-related settings are specific to a given // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are US_WEST_2 // and EU_WEST_1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Region REGION = Region.getRegion(Regions.US_WEST_2); client.setRegion(REGION); // Send the email. client.sendEmail(request); System.out.println("Email sent!"); } catch (Exception ex) { System.out.println("The email was not sent."); System.out.println("Error message: " + ex.getMessage()); } }
From source file:com.app.ses.AmazonSES.java
License:Open Source License
public void sendMailDos(String TO, String USUARIO2, String SUBJECT, String CONTENIDO, String LISTA) { System.out.println("Si imprime la llamada del la clase djscnlskdncfksdlncfksdcldsncewldn"); //operaciones con el json // Construct an object to contain the recipient address. Destination destination = new Destination().withToAddresses(new String[] { TO }); // Create the subject and body of the message. Content subject = new Content().withData(SUBJECT); Content htmlContent = new Content().withData(" <body bgcolor=\"#FFFFFF\">\n" + " <!-- HEADER -->\n" + " <table class=\"head-wrap\" bgcolor=\"red\">\n" + " <tr>\n" + " <td></td>\n" + " <td class=\"header container\" >\n" + " <div class=\"content\">\n" + " <table bgcolor=\"red\">\n" + " <tr>\n" + " <td style=\"font-size: x-large; color:white;\">\n" + " S G C o n\n" + " </td>\n" + " <td style=\"text-align: right; color:white; fon\">\n" + " Notificaciones\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " </div>\n" + " </td>\n" + " <td></td>\n" + " </tr>\n" + " </table><!-- /HEADER -->\n" + " <!-- BODY -->\n" + " <table class=\"body-wrap\">\n" + " <tr>\n" + " <td></td>\n" + " <td class=\"container\" bgcolor=\"#FFFFFF\">\n" + " <div class=\"content\">\n" + " <table>\n" + " <tr>\n" + " <td>\n" + " <h3>Hola, " + USUARIO2 + "</h3>\n" + " <p class=\"callout\">\n" + " " + CONTENIDO + "\n" + " </p>\n" + " <p>\n" + " <table style=\"font-size: medium\">\n" + " <tr>\n" + " <td>Folio: " + LISTA + "</td>\n" + " </tr>\n" + " </table>\n" + " </p> <br/>\n" + " <table>\n" + " <tr>\n" + " <td>\n" + " <p>\n" + " <a href=\"http://www.sgcon-infonavit.com\" class=\"soc-btn fb\">Ir a la aplicacin</a> \n" + " </p>\n" + " </td>\n" + " </tr>\n" + " </table\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " </div>\n" + " </td>\n" + " <td></td>\n" + " </tr>\n" + " </table>\n" + " </body>"); Body body = new Body().withHtml(htmlContent); // Create a message with the specified subject and body. Message message = new Message().withSubject(subject).withBody(body); // Assemble the email. SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination) .withMessage(message);/*from ww w. j a v a 2s .com*/ try { System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java..."); /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). * * TransferManager manages a pool of threads, so we create a * single instance and share it throughout our application. */ /*AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException( "Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); }*/ AWSCredentials awsCreds = new BasicAWSCredentials("AKIAJFO4NNHIPNTB4ZCQ", "VjYeQ9+xj3HAcLBSxxxbHTo6jy2ft0wF6tgWZXmA"); // Instantiate an Amazon SES client, which will make the service call with the supplied AWS credentials. //AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials); AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(awsCreds); // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your production // access status, sending limits, and Amazon SES identity-related settings are specific to a given // AWS region, so be sure to select an AWS region in which you set up Amazon SES. Here, we are using // the US East (N. Virginia) region. Examples of other regions that Amazon SES supports are US_WEST_2 // and EU_WEST_1. For a complete list, see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html Region REGION = Region.getRegion(Regions.US_WEST_2); client.setRegion(REGION); // Send the email. client.sendEmail(request); System.out.println("Email sent!"); } catch (Exception ex) { System.out.println("The email was not sent."); System.out.println("Error message: " + ex.getMessage()); } }
From source file:com.erudika.para.email.AWSEmailer.java
License:Apache License
@Override public boolean sendEmail(List<String> emails, String subject, String body) { if (emails != null && !emails.isEmpty() && !StringUtils.isBlank(body)) { final SendEmailRequest request = new SendEmailRequest().withSource(Config.SUPPORT_EMAIL); Destination dest = new Destination().withToAddresses(emails); request.setDestination(dest);//from w ww. j av a2s . co m Content subjContent = new Content().withData(subject); Message msg = new Message().withSubject(subjContent); // Include a body in both text and HTML formats Content textContent = new Content().withData(body).withCharset(Config.DEFAULT_ENCODING); msg.setBody(new Body().withHtml(textContent)); request.setMessage(msg); Para.asyncExecute(new Runnable() { public void run() { sesclient.sendEmail(request); } }); return true; } return false; }
From source file:com.espressologic.aws.sqs.AmazonEmailService.java
License:Open Source License
/** * build the email message/* w ww . j a va 2 s. c o m*/ * * @param messageTo * @param messageFrom * @param msgSubject * @param msgBody * @return */ public static SendEmailRequest createEmailRequestInternal(String messageTo, String messageFrom, String msgSubject, String msgBody) { Destination destination = new Destination().withToAddresses(new String[] { messageTo }); // Create the subject and body of the message. Content subject = new Content().withData(msgSubject); Content textBody = new Content().withData(msgBody); Body body = new Body().withText(textBody); // Create a message with the specified subject and body. Message message = new Message().withSubject(subject).withBody(body); // Assemble the email. return new SendEmailRequest().withSource(messageFrom).withDestination(destination).withMessage(message); }
From source file:com.hiveTown.util.AmazonSESUtil.java
License:Open Source License
public boolean sendEmail(String[] toEmail, String strBody, String strSubject, String fromAddress, String replyToAddress) throws IOException { // Construct an object to contain the recipient address. Destination destination = new Destination().withToAddresses(toEmail); // Create the subject and body of the message. Content subject = new Content().withData(strSubject); Content textBody = new Content().withData(strBody); Body body = new Body().withHtml(textBody); // Create a message with the specified subject and body. Message message = new Message().withSubject(subject).withBody(body); // Assemble the email. SendEmailRequest request = new SendEmailRequest().withSource(fromAddress).withDestination(destination) .withMessage(message).withReplyToAddresses(replyToAddress); boolean isEmailSent = false; try {//ww w .java 2 s .co m // Send the email. SendEmailResult r = this.getClient().sendEmail(request); LOGGER.info(r.toString()); isEmailSent = true; } catch (Exception ex) { LOGGER.error(ex.toString()); } return isEmailSent; }
From source file:com.kolich.aws.services.ses.impl.KolichSESClient.java
License:Open Source License
@Override public Either<HttpFailure, SendEmailResult> sendEmail(final String from, final String to, final String returnPath, final String subject, final String body) { return sendEmail( // A single TO: destination address new Destination().withToAddresses(to), // A UTF-8 encoded message and subject. new Message().withBody(new Body().withText(new Content().withData(body).withCharset(UTF_8))) .withSubject(new Content().withData(subject).withCharset(UTF_8)), // This method does not supply a reply-to address null,/*from w w w .ja v a 2 s .c o m*/ // Where to send a bounce back, if any. returnPath, // The sender's address, required from); }