Search in sources :

Example 1 with SimpleMailContent

use of org.olat.core.util.mail.model.SimpleMailContent in project OpenOLAT by OpenOLAT.

the class MailBundle method setContent.

public void setContent(String subject, String body, File... attachments) {
    List<File> attachmentList = new ArrayList<File>();
    if (attachments != null && attachments.length > 0) {
        for (File attachment : attachments) {
            if (attachment != null && attachment.exists()) {
                attachmentList.add(attachment);
            }
        }
    }
    content = new SimpleMailContent(subject, body, attachmentList);
}
Also used : SimpleMailContent(org.olat.core.util.mail.model.SimpleMailContent) ArrayList(java.util.ArrayList) File(java.io.File)

Example 2 with SimpleMailContent

use of org.olat.core.util.mail.model.SimpleMailContent in project OpenOLAT by OpenOLAT.

the class MailManagerImpl method decorateMail.

protected MailContent decorateMail(MailBundle bundle) {
    MailContent content = bundle.getContent();
    String template = getMailTemplate();
    boolean htmlTemplate = StringHelper.isHtml(template);
    String body = content.getBody();
    boolean htmlContent = StringHelper.isHtml(body);
    if (htmlTemplate && !htmlContent) {
        body = body.replace("&", "&amp;");
        body = body.replace("<", "&lt;");
        body = body.replace("\n", "<br />");
    }
    VelocityContext context = new VelocityContext();
    context.put("content", body);
    context.put("footer", MailHelper.getMailFooter(bundle));
    context.put("server", Settings.getServerContextPathURI());
    StringWriter writer = new StringWriter(2000);
    MailerResult result = new MailerResult();
    evaluate(context, template, writer, result);
    String decoratedBody;
    if (result.isSuccessful()) {
        decoratedBody = writer.toString();
    } else {
        decoratedBody = content.getBody();
    }
    return new SimpleMailContent(content.getSubject(), decoratedBody, content.getAttachments());
}
Also used : StringWriter(java.io.StringWriter) MailerResult(org.olat.core.util.mail.MailerResult) VelocityContext(org.apache.velocity.VelocityContext) SimpleMailContent(org.olat.core.util.mail.model.SimpleMailContent) SimpleMailContent(org.olat.core.util.mail.model.SimpleMailContent) MailContent(org.olat.core.util.mail.MailContent)

Example 3 with SimpleMailContent

use of org.olat.core.util.mail.model.SimpleMailContent in project OpenOLAT by OpenOLAT.

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)

Example 4 with SimpleMailContent

use of org.olat.core.util.mail.model.SimpleMailContent in project openolat by klemens.

the class MailBundle method setContent.

public void setContent(String subject, String body, File... attachments) {
    List<File> attachmentList = new ArrayList<File>();
    if (attachments != null && attachments.length > 0) {
        for (File attachment : attachments) {
            if (attachment != null && attachment.exists()) {
                attachmentList.add(attachment);
            }
        }
    }
    content = new SimpleMailContent(subject, body, attachmentList);
}
Also used : SimpleMailContent(org.olat.core.util.mail.model.SimpleMailContent) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with SimpleMailContent

use of org.olat.core.util.mail.model.SimpleMailContent in project openolat by klemens.

the class MailManagerImpl method decorateMail.

protected MailContent decorateMail(MailBundle bundle) {
    MailContent content = bundle.getContent();
    String template = getMailTemplate();
    boolean htmlTemplate = StringHelper.isHtml(template);
    String body = content.getBody();
    boolean htmlContent = StringHelper.isHtml(body);
    if (htmlTemplate && !htmlContent) {
        body = body.replace("&", "&amp;");
        body = body.replace("<", "&lt;");
        body = body.replace("\n", "<br />");
    }
    VelocityContext context = new VelocityContext();
    context.put("content", body);
    context.put("footer", MailHelper.getMailFooter(bundle));
    context.put("server", Settings.getServerContextPathURI());
    StringWriter writer = new StringWriter(2000);
    MailerResult result = new MailerResult();
    evaluate(context, template, writer, result);
    String decoratedBody;
    if (result.isSuccessful()) {
        decoratedBody = writer.toString();
    } else {
        decoratedBody = content.getBody();
    }
    return new SimpleMailContent(content.getSubject(), decoratedBody, content.getAttachments());
}
Also used : StringWriter(java.io.StringWriter) MailerResult(org.olat.core.util.mail.MailerResult) VelocityContext(org.apache.velocity.VelocityContext) SimpleMailContent(org.olat.core.util.mail.model.SimpleMailContent) SimpleMailContent(org.olat.core.util.mail.model.SimpleMailContent) MailContent(org.olat.core.util.mail.MailContent)

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