public Body unmarshall(StaxUnmarshallerContext context) throws Exception { Body body = new Body(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return body; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Text", targetDepth)) { body.setText(ContentStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Html", targetDepth)) { body.setHtml(ContentStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return body; } } } }
public Body unmarshall(StaxUnmarshallerContext context) throws Exception { Body body = new Body(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 2; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) break; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("Text", targetDepth)) { body.setText(ContentStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Html", targetDepth)) { body.setHtml(ContentStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return body; }
@Override public void send(String subject, String body, String... recipients) { Body requestBody = new Body().withText(new Content(body)); sendEmail(subject, requestBody, recipients); }
@Override public void sendAsHtml(String subject, String body, String... recipients) { Body requestBody = new Body().withHtml(new Content(body)); sendEmail(subject, requestBody, recipients); }
private Body bodyOfEmail(Email email) { if (email.getHtmlBody() != null) { Content htmlBody = new Content().withData(email.getHtmlBody()); return new Body().withHtml(htmlBody); } if (email.getTextBody() != null) { Content textBody = new Content().withData(email.getTextBody()); return new Body().withHtml(textBody); } return new Body(); }
Message message = new Message(); message.setSubject(new Content(mailMessage.getSubject()).withCharset(Charsets.UTF_8.toString())); message.setBody(new Body(new Content(mailMessage.getText()).withCharset(Charsets.UTF_8.toString())));
private void sendSimpleMail(List<String> to, List<String> cc, List<String> ci, String object, String content, boolean htmlContent) { 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); } }
public Body unmarshall(StaxUnmarshallerContext context) throws Exception { Body body = new Body(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return body; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Text", targetDepth)) { body.setText(ContentStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Html", targetDepth)) { body.setHtml(ContentStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return body; } } } }
@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); 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; } }
@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); 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); Utils.asyncExecute(new Runnable() { public void run() { sesclient.sendEmail(request); } }); return true; } return false; } }
@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); 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; } }
@Override void makeSend(String to, String subject, String msg) { String accessKey = config.readString(ConfigProperty.SES_ACCESS_KEY); String secretKey = config.readString(ConfigProperty.SES_SECRET_KEY); if (!Strings.isNullOrEmpty(accessKey)) { Destination destination = new Destination().withToAddresses(to); Content subj = new Content().withData(subject); Content textBody = new Content().withData(msg); Body body = new Body().withHtml(textBody); Message message = new Message().withSubject(subj).withBody(body); SendEmailRequest req = new SendEmailRequest().withSource(config.readString(ConfigProperty.EMAIL_DEFAULT_FROM_NAME) + " <" + config.readString(ConfigProperty.EMAIL_DEFAULT_FROM) + ">") .withDestination(destination).withMessage(message); AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.standard() .withRegion(config.readString(ConfigProperty.SES_REGION)) .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey))) .build(); try { client.sendEmail(req); } finally { client.shutdown(); } } else { throw new IllegalStateException("SES Mail provider wasn't configured well."); } }
private SendEmailRequest prepareMessage(SimpleMailMessage simpleMailMessage) { Destination destination = new Destination(); destination.withToAddresses(simpleMailMessage.getTo()); if (simpleMailMessage.getCc() != null) { destination.withCcAddresses(simpleMailMessage.getCc()); } 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; } }
private SendEmailRequest prepareMessage(SimpleMailMessage simpleMailMessage) { Destination destination = new Destination(); destination.withToAddresses(simpleMailMessage.getTo()); if (simpleMailMessage.getCc() != null) { destination.withCcAddresses(simpleMailMessage.getCc()); } 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; } }
String apiMessage = null; Body body = new Body(); if (StringUtils.isBlank(push.getHtmlContent())) { body.withText(new Content().withCharset("UTF-8").withData("-no message-"));