use of com.amazonaws.services.simpleemail.model.Content in project SimianArmy by Netflix.
the class AWSEmailNotifier method sendEmail.
@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;
}
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));
}
use of com.amazonaws.services.simpleemail.model.Content in project camel by apache.
the class SesProducer method createMessage.
private com.amazonaws.services.simpleemail.model.Message createMessage(Exchange exchange) {
com.amazonaws.services.simpleemail.model.Message message = new com.amazonaws.services.simpleemail.model.Message();
Boolean isHtmlEmail = exchange.getIn().getHeader(SesConstants.HTML_EMAIL, false, Boolean.class);
String content = exchange.getIn().getBody(String.class);
if (isHtmlEmail) {
message.setBody(new Body().withHtml(new Content().withData(content)));
} else {
message.setBody(new Body().withText(new Content().withData(content)));
}
message.setSubject(new Content(determineSubject(exchange)));
return message;
}
Aggregations