Search in sources :

Example 6 with SimpleMailContent

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);
}
Also used : StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) SimpleMailContent(org.olat.core.util.mail.model.SimpleMailContent) File(java.io.File)

Aggregations

SimpleMailContent (org.olat.core.util.mail.model.SimpleMailContent)6 File (java.io.File)4 StringWriter (java.io.StringWriter)4 VelocityContext (org.apache.velocity.VelocityContext)4 ArrayList (java.util.ArrayList)2 MailContent (org.olat.core.util.mail.MailContent)2 MailerResult (org.olat.core.util.mail.MailerResult)2