use of org.olat.core.util.mail.model.SimpleMailContent in project openolat by klemens.
the class MailManagerImpl method createWithContext.
protected MailContent createWithContext(Identity recipient, MailTemplate template, MailerResult result) {
VelocityContext context;
if (template != null && template.getContext() != null) {
context = new VelocityContext(template.getContext());
} else {
context = new VelocityContext();
}
template.putVariablesInMailContext(context, recipient);
// merge subject template with context variables
StringWriter subjectWriter = new StringWriter();
evaluate(context, template.getSubjectTemplate(), subjectWriter, result);
// merge body template with context variables
StringWriter bodyWriter = new StringWriter();
evaluate(context, template.getBodyTemplate(), bodyWriter, result);
// check for errors - exit
if (result.getReturnCode() != MailerResult.OK) {
return null;
}
String subject = subjectWriter.toString();
String body = bodyWriter.toString();
List<File> checkedFiles = MailHelper.checkAttachments(template.getAttachments(), result);
File[] attachments = checkedFiles.toArray(new File[checkedFiles.size()]);
return new SimpleMailContent(subject, body, attachments);
}
Aggregations