List of usage examples for com.amazonaws.services.simpleemail AmazonSimpleEmailServiceClient sendEmail
@Override
public SendEmailResult sendEmail(SendEmailRequest request)
Composes an email message and immediately queues it for sending.
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 www . j ava 2 s. 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 [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.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 av 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 [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 www . j a v a 2 s . c o 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.espressologic.aws.sqs.AmazonEmailService.java
License:Open Source License
/** * send email using credentials and region * * @param request/*from w w w.j a v a 2s . co m*/ * @throws Exception */ public static void sendEmalRequest(SendEmailRequest request) throws Exception { 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. */ createAWSCredentials(); // 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(getMyRegion()); 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()); throw ex; } }
From source file:com.netflix.ice.processor.BillingFileProcessor.java
License:Apache License
private void sendOndemandCostAlert() { if (ondemandThreshold == null || StringUtils.isEmpty(fromEmail) || StringUtils.isEmpty(alertEmails) || endMilli < lastAlertMillis() + AwsUtils.hourMillis * 24) return;//from ww w. ja va 2 s . co m Map<Long, Map<Ec2InstanceReservationPrice.Key, Double>> ondemandCosts = getOndemandCosts( lastAlertMillis() + AwsUtils.hourMillis); Long maxHour = null; double maxTotal = ondemandThreshold; for (Long hour : ondemandCosts.keySet()) { double total = 0; for (Double value : ondemandCosts.get(hour).values()) total += value; if (total > maxTotal) { maxHour = hour; maxTotal = total; } } if (maxHour != null) { NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); String subject = String.format("Alert: Ondemand cost per hour reached $%s at %s", numberFormat.format(maxTotal), AwsUtils.dateFormatter.print(maxHour)); StringBuilder body = new StringBuilder(); body.append(String.format("Total ondemand cost $%s at %s:<br><br>", numberFormat.format(maxTotal), AwsUtils.dateFormatter.print(maxHour))); TreeMap<Double, String> costs = Maps.newTreeMap(); for (Map.Entry<Ec2InstanceReservationPrice.Key, Double> entry : ondemandCosts.get(maxHour).entrySet()) { costs.put(entry.getValue(), entry.getKey().region + " " + entry.getKey().usageType + ": "); } for (Double cost : costs.descendingKeySet()) { if (cost > 0) body.append(costs.get(cost)).append("$" + numberFormat.format(cost)).append("<br>"); } body.append("<br>Please go to <a href=\"" + urlPrefix + "dashboard/reservation#usage_cost=cost&groupBy=UsageType&product=ec2_instance&operation=OndemandInstances\">Ice</a> for details."); SendEmailRequest request = new SendEmailRequest(); request.withSource(fromEmail); List<String> emails = Lists.newArrayList(alertEmails.split(",")); request.withDestination(new Destination(emails)); request.withMessage( new Message(new Content(subject), new Body().withHtml(new Content(body.toString())))); AmazonSimpleEmailServiceClient emailService = AwsUtils.getAmazonSimpleEmailServiceClient(); try { emailService.sendEmail(request); updateLastAlertMillis(endMilli); logger.info("updateLastAlertMillis " + endMilli); } catch (Exception e) { logger.error("Error in sending alert emails", e); } } }
From source file:com.prd.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 ww . j a va 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 [default] * credential profile by reading from the credentials file located at * (/Users/prabhjitsingh/.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("default").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/prabhjitsingh/.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.solomon.aws.service.AwsMailServ.java
public void sendMail() { Destination destination = new Destination().withToAddresses(new String[] { to }); Content subject = new Content().withData(topic); Content textBody = new Content().withData(body); Body mailBody = new Body().withText(textBody); Message message = new Message().withSubject(subject).withBody(mailBody); SendEmailRequest request = new SendEmailRequest().withSource(from).withDestination(destination) .withMessage(message);/*ww w.ja v a 2 s.c o 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 [New US East (Virginia) Profile] * credential profile by reading from the credentials file located at * (/Users/zhao0677/.aws/credentials). * * TransferManager manages a pool of threads, so we create a * single instance and share it throughout our application. */ try { AWSCredentials credentials = AwsUtil.getAwsCredentials(); AmazonSimpleEmailServiceClient client = AwsUtil.getAwsEmailServClient(credentials); Region REGION = Region.getRegion(AwsUtil.DEVELOPER_REGION); client.setRegion(REGION); // Send the email. client.sendEmail(request); System.out.println("Email sent!"); } 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, and is in valid format.", e); } } catch (Exception ex) { System.out.println("The email was not sent."); System.out.println("Error message: " + ex.getMessage()); } }
From source file:io.kodokojo.service.aws.SesEmailSender.java
License:Open Source License
@Override public void send(List<String> to, List<String> cc, List<String> ci, String object, String content, boolean htmlContent) { if (CollectionUtils.isEmpty(to)) { throw new IllegalArgumentException("to must be defined."); }//from ww w . java 2s . c om if (isBlank(content)) { throw new IllegalArgumentException("content must be defined."); } Destination destination = new Destination().withToAddresses(to).withBccAddresses(ci).withCcAddresses(cc); Content subject = new Content().withData(object); Content bodyContent = new Content().withData(content); Body body; if (htmlContent) { body = new Body().withHtml(bodyContent); } else { body = new Body().withText(bodyContent); } Message message = new Message().withSubject(subject).withBody(body); SendEmailRequest request = new SendEmailRequest().withSource(from).withDestination(destination) .withMessage(message); try { AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(); client.setRegion(region); client.sendEmail(request); } catch (Exception e) { LOGGER.error("Unable to send email to {} with subject '{}'", StringUtils.join(to, ","), subject, e); } }
From source file:jp.co.hde.mail.ses.AmazonSESSample.java
License:Apache 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(TEXT_BODY); Content htmlBody = new Content().withData(HTML_BODY); Body body = new Body().withHtml(htmlBody); // Create a message with the specified subject and body. Message message = new Message().withSubject(subject).withBody(body); com.amazonaws.services.simpleemail.model. // Assemble the email. SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination) .withMessage(message); try {//from w w w . jav a2 s.c o m System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java..."); // Instantiate an Amazon SES client, which will make the service call. The service call requires your AWS credentials. // Because we're not providing an argument when instantiating the client, the SDK will attempt to find your AWS credentials // using the default credential provider chain. The first place the chain looks for the credentials is in environment variables // AWS_ACCESS_KEY_ID and AWS_SECRET_KEY. // For more information, see http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(); // Choose the AWS region of the Amazon SES endpoint you want to connect to. Note that your sandbox // 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 region. Examples of other regions that Amazon SES supports are US_EAST_1 // 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:net.smartcosmos.plugin.service.aws.email.AwsEmailService.java
License:Apache License
@Override public void sendEmail(String to, String subject, String plainMessage, String htmlMessage) { String from = context.getConfiguration().getAdminEmailAddress(); SendEmailRequest request = new SendEmailRequest().withSource(from); List<String> toAddresses = new ArrayList<String>(); toAddresses.add(to);/*from ww w.j a va 2s .c o m*/ Destination destination = new Destination().withToAddresses(toAddresses); request.setDestination(destination); Content subjContent = new Content().withData(subject); Message msg = new Message().withSubject(subjContent); Content textContent = new Content().withData(plainMessage); Content htmlContent = new Content().withData(htmlMessage); Body body = new Body().withHtml(htmlContent).withText(textContent); msg.setBody(body); request.setMessage(msg); AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials); try { client.sendEmail(request); LOG.info("Registration confirmation sent to email " + to); } catch (Exception e) { e.printStackTrace(); } }