Search in sources :

Example 1 with MailContent

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

the class MailManagerImpl method makeMailBundle.

@Override
public MailBundle makeMailBundle(MailContext ctxt, Identity recipientTO, MailTemplate template, Identity sender, String metaId, MailerResult result) {
    MailBundle bundle;
    if (MailHelper.isDisabledMailAddress(recipientTO, result)) {
        // email disabled, nothing to do
        bundle = null;
    } else {
        MailContent msg = createWithContext(recipientTO, template, result);
        if (msg != null && result.getReturnCode() == MailerResult.OK) {
            // send mail
            bundle = new MailBundle();
            bundle.setContext(ctxt);
            bundle.setFromId(sender);
            bundle.setToId(recipientTO);
            bundle.setMetaId(metaId);
            bundle.setContent(msg);
        } else {
            bundle = null;
        }
    }
    return bundle;
}
Also used : MailBundle(org.olat.core.util.mail.MailBundle) SimpleMailContent(org.olat.core.util.mail.model.SimpleMailContent) MailContent(org.olat.core.util.mail.MailContent)

Example 2 with MailContent

use of org.olat.core.util.mail.MailContent 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("&", "&");
        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 MailContent

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

the class MailManagerImpl method makeMailBundle.

@Override
public MailBundle makeMailBundle(MailContext ctxt, Identity recipientTO, MailTemplate template, Identity sender, String metaId, MailerResult result) {
    MailBundle bundle;
    if (MailHelper.isDisabledMailAddress(recipientTO, result)) {
        // email disabled, nothing to do
        bundle = null;
    } else {
        MailContent msg = createWithContext(recipientTO, template, result);
        if (msg != null && result.getReturnCode() == MailerResult.OK) {
            // send mail
            bundle = new MailBundle();
            bundle.setContext(ctxt);
            bundle.setFromId(sender);
            bundle.setToId(recipientTO);
            bundle.setMetaId(metaId);
            bundle.setContent(msg);
        } else {
            bundle = null;
        }
    }
    return bundle;
}
Also used : MailBundle(org.olat.core.util.mail.MailBundle) SimpleMailContent(org.olat.core.util.mail.model.SimpleMailContent) MailContent(org.olat.core.util.mail.MailContent)

Example 4 with MailContent

use of org.olat.core.util.mail.MailContent 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

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