public Message unmarshall(StaxUnmarshallerContext context) throws Exception { Message message = new Message(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return message; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("Subject", targetDepth)) { message.setSubject(ContentStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Body", targetDepth)) { message.setBody(BodyStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return message; } } } }
/** * Constructs a new Message object. Callers should use the setter or fluent setter (with...) methods to initialize * any additional object members. * * @param subject * The subject of the message: A short summary of the content, which will appear in the recipient's inbox. * @param body * The message body. */ public Message(Content subject, Body body) { setSubject(subject); setBody(body); }
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); emailService.sendEmail(request); } }
@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; } }
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; } }
/** * <p> * The message body. * </p> * * @param body * The message body. * @return Returns a reference to this object so that method calls can be chained together. */ public Message withBody(Body body) { setBody(body); return this; }
/** * <p> * The subject of the message: A short summary of the content, which will appear in the recipient's inbox. * </p> * * @param subject * The subject of the message: A short summary of the content, which will appear in the recipient's inbox. * @return Returns a reference to this object so that method calls can be chained together. */ public Message withSubject(Content subject) { setSubject(subject); return this; }
if (other.getMessage() == null ^ this.getMessage() == null) return false; if (other.getMessage() != null && other.getMessage().equals(this.getMessage()) == false) return false; if (other.getReplyToAddresses() == null ^ this.getReplyToAddresses() == null)
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); } }
@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; } }
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; } }
/** * Constructs a new Message object. Callers should use the setter or fluent * setter (with...) methods to initialize any additional object members. * * @param subject <p> * The subject of the message: A short summary of the content, * which will appear in the recipient's inbox. * </p> * @param body <p> * The message body. * </p> */ public Message(Content subject, Body body) { setSubject(subject); setBody(body); }
/** * <p> * The message body. * </p> * * @param body * The message body. * @return Returns a reference to this object so that method calls can be chained together. */ public Message withBody(Body body) { setBody(body); return this; }
/** * <p> * The subject of the message: A short summary of the content, which will appear in the recipient's inbox. * </p> * * @param subject * The subject of the message: A short summary of the content, which will appear in the recipient's inbox. * @return Returns a reference to this object so that method calls can be chained together. */ public Message withSubject(Content subject) { setSubject(subject); return this; }
if (other.getMessage() == null ^ this.getMessage() == null) return false; if (other.getMessage() != null && other.getMessage().equals(this.getMessage()) == false) return false; if (other.getReplyToAddresses() == null ^ this.getReplyToAddresses() == null)
Message message = new Message().withSubject(subject).withBody(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); Utils.asyncExecute(new Runnable() { public void run() { sesclient.sendEmail(request); } }); return true; } return false; } }
public Message unmarshall(StaxUnmarshallerContext context) throws Exception { Message message = new Message(); 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("Subject", targetDepth)) { message.setSubject(ContentStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("Body", targetDepth)) { message.setBody(BodyStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { break; } } } return message; }
Content subjectContent = new Content().withCharset("UTF-8").withData(subject); sendEmailRequest.setMessage(new Message(subjectContent, body));
/** * Constructs a new Message object. Callers should use the setter or fluent setter (with...) methods to initialize * any additional object members. * * @param subject * The subject of the message: A short summary of the content, which will appear in the recipient's inbox. * @param body * The message body. */ public Message(Content subject, Body body) { setSubject(subject); setBody(body); }