List of usage examples for com.amazonaws.services.simpleemail.model SendEmailRequest SendEmailRequest
public SendEmailRequest(String source, Destination destination, Message message)
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 .ja v a 2 s .com*/ 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.irurueta.server.commons.email.AWSMailSender.java
License:Apache License
/** * Method to send a text email.//from w w w . ja va 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.netflix.simianarmy.aws.AWSEmailNotifier.java
License:Apache License
@Override public void sendEmail(String to, String subject, String body) { if (!isValidEmail(to)) { LOGGER.error(String.format("The destination email address %s is not valid, no email is sent.", to)); return;/*from w ww .java 2 s . com*/ } if (sesClient == null) { String msg = "The email client is not set."; LOGGER.error(msg); throw new RuntimeException(msg); } Destination destination = new Destination().withToAddresses(to).withCcAddresses(getCcAddresses(to)); Content subjectContent = new Content(subject); Content bodyContent = new Content(); Body msgBody = new Body(bodyContent); msgBody.setHtml(new Content(body)); Message msg = new Message(subjectContent, msgBody); String sourceAddress = getSourceAddress(to); SendEmailRequest request = new SendEmailRequest(sourceAddress, destination, msg); request.setReturnPath(sourceAddress); LOGGER.debug(String.format("Sending email with subject '%s' to %s", subject, to)); SendEmailResult result = null; try { result = sesClient.sendEmail(request); } catch (Exception e) { throw new RuntimeException(String.format("Failed to send email to %s", to), e); } LOGGER.info( String.format("Email to %s, result id is %s, subject is %s", to, result.getMessageId(), subject)); }
From source file:fr.xebia.cloud.amazon.aws.iam.AmazonAwsIamAccountCreator.java
License:Apache License
/** * Send email with Amazon Simple Email Service. * <p/>/*www. j a v a 2 s. c o m*/ * <p/> * Please note that the sender (ie 'from') must be a verified address (see * {@link AmazonSimpleEmailService#verifyEmailAddress(com.amazonaws.services.simpleemail.model.VerifyEmailAddressRequest)} * ). * <p/> * <p/> * Please note that the sender is a CC of the meail to ease support. * <p/> * * @param subject * @param body * @param from * @param toAddresses */ public void sendEmail(String subject, String body, String from, String... toAddresses) { SendEmailRequest sendEmailRequest = new SendEmailRequest( // from, // new Destination().withToAddresses(toAddresses).withCcAddresses(from), // new Message(new Content(subject), // new Body(new Content(body)))); SendEmailResult sendEmailResult = ses.sendEmail(sendEmailRequest); System.out.println(sendEmailResult); }
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 {/*www.ja va 2s. com*/ 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.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);/* www.jav a2s.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);//from w w w . jav a2 s . co 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); }
From source file:org.springframework.cloud.aws.mail.simplemail.SimpleEmailServiceMailSender.java
License:Apache License
private SendEmailRequest prepareMessage(SimpleMailMessage simpleMailMessage) { Destination destination = new Destination(); destination.withToAddresses(simpleMailMessage.getTo()); if (simpleMailMessage.getCc() != null) { destination.withCcAddresses(simpleMailMessage.getCc()); }//from w w w . j a v a2 s .co m if (simpleMailMessage.getBcc() != null) { destination.withBccAddresses(simpleMailMessage.getBcc()); } Content subject = new Content(simpleMailMessage.getSubject()); Body body = new Body(new Content(simpleMailMessage.getText())); SendEmailRequest emailRequest = new SendEmailRequest(simpleMailMessage.getFrom(), destination, new Message(subject, body)); if (StringUtils.hasText(simpleMailMessage.getReplyTo())) { emailRequest.withReplyToAddresses(simpleMailMessage.getReplyTo()); } return emailRequest; }
From source file:org.springframework.integration.aws.ses.core.AmazonSESMailSenderImpl.java
License:Apache License
public void send(AmazonSESSimpleMailMessage[] messages) { AmazonSESSimpleMailMessage currentMessage = null; if (messages != null && messages.length > 0) { try {//from ww w .j a v a2s .c o m for (AmazonSESSimpleMailMessage message : messages) { if (message != null) { //Construct a mail message from the given parameters currentMessage = message; //First the subject Content subject = new Content(message.getSubject()); //Then the body content Content body = new Content(message.getMessage()); //Construct the Mail Message from the above two Body messageBody; if (message.isHtml()) messageBody = new Body().withHtml(body); else messageBody = new Body().withText(body); //The final mail message from the body and subject Message finalMessage = new Message(subject, messageBody); //Destination of the email Destination destination = new Destination().withToAddresses(message.getToList()) .withCcAddresses(message.getCcList()).withBccAddresses(message.getBccList()); //Now the SES mail request SendEmailRequest request = new SendEmailRequest(message.getFrom(), destination, finalMessage).withReplyToAddresses(message.getReplyTo()); emailService.sendEmail(request); } } } catch (Exception e) { //caught Exception throw new AmazonSESMailSendException(credentials.getAccessKey(), "Exception Caught with message \"" + e.getMessage() + "\" while sending mail", e, currentMessage); } } }
From source file:spikes.email.AmazonSimpleEmailServiceSpike.java
License:Open Source License
public static void main(String[] args) throws IOException { PropertiesCredentials credentials = new PropertiesCredentials( AmazonSimpleEmailServiceSpike.class.getResourceAsStream("AwsCredentials.properties")); AmazonSimpleEmailService service = new AmazonSimpleEmailServiceClient(credentials); verifyAddressIfNecessary(service, FROM); Destination destination = new Destination(Arrays.asList(TO)); Content subject = new Content(SUBJECT); Body body = new Body().withHtml(new Content(BODY)); Message message = new Message(subject, body); service.sendEmail(new SendEmailRequest(from(), destination, message)); System.exit(0);/*from w w w. j a v a2s. c om*/ }