List of usage examples for com.amazonaws.services.simpleemail.model Destination Destination
public Destination(java.util.List<String> toAddresses)
From source file:com.devnexus.ting.core.service.integration.AmazonSesSender.java
License:Apache License
public void sendUsingSendgrid(GenericEmail email) { final Destination destination = new Destination(email.getTo()); destination.setCcAddresses(email.getCc()); final Content subject = new Content(email.getSubject()); final Content htmlContent = new Content().withData(email.getHtml()); final Content textContent = new Content().withData(email.getText()); final Body body = new Body().withHtml(htmlContent).withText(textContent); final Message message = new Message().withSubject(subject).withBody(body); final SendEmailRequest request = new SendEmailRequest().withSource(email.getFrom()) .withDestination(destination).withMessage(message); final Region REGION = Region.getRegion(Regions.US_EAST_1); client.setRegion(REGION);/* w w w . j a v a 2s . c o m*/ // Send the email. client.sendEmail(request); LOGGER.info("Email sent to {}", email.getTo()); }
From source file:com.github.trask.sandbox.mail.impl.AmazonMailService.java
License:Apache License
public Future<Void> sendMail(String from, String to, String subject, String htmlBody, String textBody) { logger.debug("sendMail(): from={}", from); logger.debug("sendMail(): to={}", to); logger.debug("sendMail(): subject={}", subject); logger.debug("sendMail(): htmlBody={}", htmlBody); logger.debug("sendMail(): textBody={}", textBody); Body body = new Body(new Content(textBody)).withHtml(new Content(htmlBody)); Message message = new Message(new Content(subject), body); SendEmailRequest sendEmailRequest = new SendEmailRequest(); sendEmailRequest.setSource(from);//from w w w .j a v a 2 s . c o m sendEmailRequest.setDestination(new Destination(Collections.singletonList(to))); sendEmailRequest.setMessage(message); Future<SendEmailResult> future = simpleEmailServiceAsync.sendEmailAsync(sendEmailRequest); return new VoidFutureWrapper(future); }
From source file:com.irurueta.server.commons.email.AWSMailSender.java
License:Apache License
/** * Method to send a text email.//from www. ja v a 2 s . co m * @param m email message to be sent. * @return id of message that has been sent. * @throws MailNotSentException if mail couldn't be sent. */ private String sendTextEmail(AWSTextEmailMessage m) throws MailNotSentException { String messageId; long currentTimestamp = System.currentTimeMillis(); prepareClient(); if (!mEnabled) { //don't send message if not enabled return null; } try { synchronized (this) { //prevents throttling checkQuota(currentTimestamp); Destination destination = new Destination(m.getTo()); if (m.getBCC() != null && !m.getBCC().isEmpty()) { destination.setBccAddresses(m.getBCC()); } if (m.getCC() != null && !m.getCC().isEmpty()) { destination.setCcAddresses(m.getCC()); } //if no subject, set to empty string to avoid errors if (m.getSubject() == null) { m.setSubject(""); } Message message = new Message(); m.buildContent(message); SendEmailResult result = mClient .sendEmail(new SendEmailRequest(mMailFromAddress, destination, message)); messageId = result.getMessageId(); //update timestamp of last sent email mLastSentMailTimestamp = System.currentTimeMillis(); //wait to avoid throwttling exceptions to avoid making any //further requests this.wait(mWaitIntervalMillis); } } catch (Throwable t) { throw new MailNotSentException(t); } return messageId; }
From source file:com.irurueta.server.commons.email.AWSTextEmailMessage.java
License:Apache License
/** * Builds email content to be sent using an email sender. * @param message instance where content must be set. * @throws EmailException if setting mail content fails. *//*from w ww. j a v a 2 s.co m*/ @Override protected void buildContent(Message message) throws EmailException { Destination destination = new Destination(getTo()); if (getBCC() != null && !getBCC().isEmpty()) { destination.setBccAddresses(getBCC()); } if (getCC() != null && !getCC().isEmpty()) { destination.setCcAddresses(getCC()); } if (getSubject() != null) { Content subject = new Content(getSubject()); //set utf-8 enconding to support all languages subject.setCharset("UTF-8"); message.setSubject(subject); } if (getText() != null) { Body body = new Body(); Content content = new Content(getText()); //set utf-8 enconding to support all languages content.setCharset("UTF-8"); body.setText(content); message.setBody(body); } }
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 w w w .ja v a 2s.c o 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:jp.classmethod.aws.petrucci.Tasks.java
License:Apache License
@Scheduled(cron = "0 */2 * * * *") public void reportS3AndEC2() { logger.info("report start"); DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); StringBuilder sb = new StringBuilder(); logger.info("check S3 buckets"); sb.append("== S3 Buckets ==\n"); try {/*w w w. ja va2 s .co m*/ for (Bucket bucket : s3.listBuckets()) { sb.append( String.format("%s (created:%s)%n", bucket.getName(), df.format(bucket.getCreationDate()))); } } catch (AmazonClientException e) { logger.error("unexpected exception", e); } sb.append("\n"); logger.info("check EC2 instances"); sb.append("== EC2 Instances ==").append("\n"); try { DescribeInstancesResult result = ec2.describeInstances(); for (Reservation reservation : result.getReservations()) { for (Instance instance : reservation.getInstances()) { sb.append(String.format("%s %s %s%n", instance.getInstanceId(), instance.getImageId(), instance.getInstanceType(), instance.getInstanceLifecycle())); } } } catch (AmazonClientException e) { logger.error("unexpected exception", e); } if (logger.isInfoEnabled()) { Scanner scanner = null; try { scanner = new Scanner(sb.toString()); while (scanner.hasNextLine()) { logger.info("{}", scanner.nextLine()); } } finally { if (scanner != null) { scanner.close(); } } } logger.info("send report mail"); ses.sendEmail(new SendEmailRequest(mailaddress, new Destination(Collections.singletonList(mailaddress)), new Message(new Content("S3 & EC2 Report"), new Body(new Content(sb.toString()))))); logger.info("report end"); }
From source file:org.apache.camel.component.aws.ses.SesProducer.java
License:Apache License
@SuppressWarnings("unchecked") private Destination determineTo(Exchange exchange) { List<String> to = exchange.getIn().getHeader(SesConstants.TO, List.class); if (to == null) { to = getConfiguration().getTo(); }/*from w w w. j a va 2s. c o m*/ return new Destination(to); }
From source file:org.duracloud.notification.AmazonEmailer.java
License:Apache License
private void sendEmail(String subject, Body body, String... recipients) { Destination destination = new Destination(Arrays.asList(recipients)); Message msg = new Message().withBody(body).withSubject(new Content(subject)); SendEmailRequest request = new SendEmailRequest().withSource(fromAddress).withDestination(destination) .withMessage(msg);// ww w . ja va2s . c o m emailService.sendEmail(request); }
From source file:org.onebusaway.admin.service.impl.EmailServiceImpl.java
License:Apache License
@Override public void sendAsync(String to, String from, String subject, StringBuffer messageBody) { List<String> toAddresses = new ArrayList<String>(); for (String address : to.split(",")) { toAddresses.add(address);/*from ww w. j av a2 s . c o m*/ } Destination destination = new Destination(toAddresses); Body body = new Body(); body.setText(new Content(messageBody.toString())); Message message = new Message(new Content(subject), body); SendEmailRequest sendEmailRequest = new SendEmailRequest(from, destination, message); Future<SendEmailResult> result = _eClient.sendEmailAsync(sendEmailRequest); _log.info("sent email to " + to + " with finished=" + result.isDone()); }
From source file:org.onebusaway.admin.service.impl.EmailServiceImpl.java
License:Apache License
public void sendSES(String to, String from, String subject, StringBuffer messageBody) { List<String> toAddresses = new ArrayList<String>(); for (String address : to.split(",")) { toAddresses.add(address);/* ww w . j a v a 2 s . c o m*/ } Destination destination = new Destination(toAddresses); Body body = new Body(); body.setText(new Content(messageBody.toString())); Message message = new Message(new Content(subject), body); SendEmailRequest sendEmailRequest = new SendEmailRequest(from, destination, message); SendEmailResult result = _eClient.sendEmail(sendEmailRequest); _log.info("sent email to " + to + " with result=" + result); }