use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class TaskFolderCallback method sendNotificationEmail.
private void sendNotificationEmail(UserRequest ureq, MailTemplate mailTemplate, List<Identity> recipients) {
// send the notification mail
if (mailTemplate != null) {
Identity sender = ureq.getIdentity();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailerResult result = new MailerResult();
String metaId = UUID.randomUUID().toString().replace("-", "");
MailBundle[] bundles = mailManager.makeMailBundles(context, recipients, mailTemplate, sender, metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, sender, mailTemplate, sender, metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
}
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class ReturnboxFullAccessCallback method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == dropboxFolderRunController) {
if (event instanceof FolderEvent) {
FolderEvent folderEvent = (FolderEvent) event;
if (folderEvent.getCommand().equals(FolderEvent.DELETE_EVENT)) {
UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
// log entry for this file
Identity coach = ureq.getIdentity();
Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
am.appendToUserNodeLog(node, coach, student, "FILE DELETED: " + folderEvent.getFilename());
}
}
} else if (source == returnboxFolderRunController) {
if (event instanceof FolderEvent) {
FolderEvent folderEvent = (FolderEvent) event;
if (folderEvent.getCommand().equals(FolderEvent.UPLOAD_EVENT) || folderEvent.getCommand().equals(FolderEvent.NEW_FILE_EVENT)) {
UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
// log entry for this file
Identity coach = ureq.getIdentity();
Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
if (node instanceof AssessableCourseNode) {
AssessableCourseNode acn = (AssessableCourseNode) node;
AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
acn.updateUserScoreEvaluation(eval, userCourseEnv, coach, false, Role.coach);
}
}
am.appendToUserNodeLog(node, coach, student, "FILE UPLOADED: " + folderEvent.getFilename());
String toMail = UserManager.getInstance().getUserDisplayEmail(student, ureq.getLocale());
OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseNode.class, Long.valueOf(node.getIdent()));
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
BusinessControl bc = BusinessControlFactory.getInstance().createBusinessControl(ce, getWindowControl().getBusinessControl());
String link = BusinessControlFactory.getInstance().getAsURIString(bc, true);
log.debug("DEBUG : Returnbox notification email with link=" + link);
String subject = translate("returnbox.email.subject");
String body = translate("returnbox.email.body", new String[] { userCourseEnv.getCourseEnvironment().getCourseTitle(), node.getShortTitle(), folderEvent.getFilename(), link });
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setToId(student);
bundle.setContent(subject, body);
MailerResult result = CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
if (result.getReturnCode() > 0) {
am.appendToUserNodeLog(node, coach, student, "MAIL SEND FAILED TO:" + toMail + "; MailReturnCode: " + result.getReturnCode());
log.warn("Could not send email 'returnbox notification' to " + student + "with email=" + toMail);
} else {
log.info("Send email 'returnbox notification' to " + student + "with email=" + toMail);
}
}
} else if (FolderCommand.FOLDERCOMMAND_FINISHED == event) {
if (node instanceof AssessableCourseNode) {
AssessableCourseNode acn = (AssessableCourseNode) node;
AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
if (eval == null) {
eval = AssessmentEvaluation.EMPTY_EVAL;
}
if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
acn.updateUserScoreEvaluation(eval, userCourseEnv, getIdentity(), false, Role.coach);
fireEvent(ureq, Event.CHANGED_EVENT);
}
}
}
} else if (source == statusForm) {
if (event == Event.DONE_EVENT) {
// get identity not from request (this would be an author)
StatusManager.getInstance().saveStatusFormData(statusForm, node, userCourseEnv);
}
} else if (source == dialogBoxController) {
if (DialogBoxUIFactory.isYesEvent(event) && assignedTask != null) {
// cancel task assignment, and show "no task assigned to user"
removeAssignedTask(userCourseEnv, userCourseEnv.getIdentityEnvironment().getIdentity());
// update UI
myContent.contextPut("assignedtask", null);
}
}
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class PublishController method sendInvitation.
private void sendInvitation(List<Identity> identities, MailTemplate mailTemplate) {
ContactList contactList = new ContactList("Invitation");
contactList.addAllIdentites(identities);
boolean success = false;
try {
MailContext context = new MailContextImpl(binder, null, getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFromId(getIdentity());
bundle.setContactList(contactList);
bundle.setContent(mailTemplate.getSubjectTemplate(), mailTemplate.getBodyTemplate());
MailerResult result = mailManager.sendMessage(bundle);
success = result.isSuccessful();
} catch (Exception e) {
logError("Error on sending invitation mail to contactlist, invalid address.", e);
}
if (success) {
showInfo("invitation.mail.success");
} else {
showError("invitation.mail.failure");
}
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class MailTest method testVelocityTemplate.
/**
* this is more a playground method to understand the evaluate method than a
* rela testcase
*/
@Test
public void testVelocityTemplate() {
//
VelocityContext context = new VelocityContext();
// good case
StringWriter writer = new StringWriter();
context.put("foo", "bar");
String template = "foo $foo";
MailerResult result = new MailerResult();
((MailManagerImpl) mailManager).evaluate(context, template, writer, result);
assertEquals(MailerResult.OK, result.getReturnCode());
assertEquals("foo bar", writer.toString());
writer = new StringWriter();
template = "foo foo";
((MailManagerImpl) mailManager).evaluate(context, template, writer, result);
assertEquals(MailerResult.OK, result.getReturnCode());
assertEquals("foo foo", writer.toString());
writer = new StringWriter();
template = "foo $$foo";
((MailManagerImpl) mailManager).evaluate(context, template, writer, result);
assertEquals(MailerResult.OK, result.getReturnCode());
assertEquals("foo $bar", writer.toString());
writer = new StringWriter();
template = "foo $ foo";
((MailManagerImpl) mailManager).evaluate(context, template, writer, result);
assertEquals(MailerResult.OK, result.getReturnCode());
assertEquals("foo $ foo", writer.toString());
writer = new StringWriter();
template = "foo $ foo";
((MailManagerImpl) mailManager).evaluate(context, template, writer, result);
assertEquals(MailerResult.OK, result.getReturnCode());
assertEquals("foo $ foo", writer.toString());
writer = new StringWriter();
template = "foo #foo \n##sdf jubla";
((MailManagerImpl) mailManager).evaluate(context, template, writer, result);
assertEquals(MailerResult.OK, result.getReturnCode());
assertEquals("foo #foo \n", writer.toString());
writer = new StringWriter();
template = "foo #if(true)\n#end";
((MailManagerImpl) mailManager).evaluate(context, template, writer, result);
assertEquals(MailerResult.OK, result.getReturnCode());
assertEquals("foo ", writer.toString());
// illegal templates: unclosed if-else statement
writer = new StringWriter();
template = "foo #if";
((MailManagerImpl) mailManager).evaluate(context, template, writer, result);
assertEquals(MailerResult.TEMPLATE_PARSE_ERROR, result.getReturnCode());
assertEquals("", writer.toString());
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class MailTest method sendMailAsSeparateMails.
public MailerResult sendMailAsSeparateMails(MailContext mCtxt, List<Identity> recipientsTO, Identity recipientCC, MailTemplate template, Identity sender, String metaId) {
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(mCtxt, recipientsTO, template, sender, metaId, result);
result.append(mailManager.sendMessage(bundles));
if (recipientCC != null) {
MailBundle ccBundle = mailManager.makeMailBundle(mCtxt, recipientCC, template, sender, metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
return result;
}
Aggregations