use of com.khartec.waltz.common.StringUtilities in project waltz by khartec.
the class WaltzEmailer method sendEmail.
public void sendEmail(String subject, String body, String[] to) {
Checks.checkNotEmpty(subject, "subject cannot be empty");
Checks.checkNotEmpty(body, "body cannot be empty");
Checks.checkNotEmpty(to, "to cannot be empty");
Checks.checkAll(to, StringUtilities::notEmpty, "email address cannot be empty");
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true);
message.setSubject(subject);
message.setFrom(fromEmail);
message.setBcc(to);
message.addAttachment("waltz.png", IOUtilities.getFileResource("/images/waltz.png"));
message.addAttachment("client-logo", IOUtilities.getFileResource("/templates/images/client-logo.png"));
Map model = new HashMap();
model.put("body", body);
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
try (InputStreamReader templateReader = new InputStreamReader(IOUtilities.getFileResource(DEFAULT_EMAIL_TEMPLATE_LOCATION).getInputStream())) {
Template template = new Template("template", templateReader, cfg);
String text = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
message.setText(text, true);
}
};
this.mailSender.send(preparator);
}
Aggregations