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);
}
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("&", "&");
body = body.replace("<", "<");
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());
}
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);
}
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);
}
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("&", "&");
body = body.replace("<", "<");
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());
}
Aggregations