use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class BusinessGroupMailing method sendEmail.
protected static void sendEmail(Identity ureqIdentity, Identity identity, BusinessGroupShort group, MailType type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
BusinessGroupModule groupModule = CoreSpringFactory.getImpl(BusinessGroupModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!groupModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
// booking by myself
if (type != null && type == MailType.addParticipant && ureqIdentity != null && ureqIdentity.equals(identity)) {
template = BGMailHelper.createAddMyselfMailTemplate(group, ureqIdentity);
} else {
template = getDefaultTemplate(type, group, ureqIdentity);
}
} else if (group != null && template.getContext() != null && needTemplateEnhancement(template)) {
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
template = new MailTemplateDelegate(template, group, repoEntries);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[BusinessGroup:" + group.getKey() + "]");
}
MailerResult result = new MailerResult();
String metaId = mailing != null ? mailing.getUuid() : null;
MailManager mailService = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailService.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailService.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class BusinessGroupServiceImpl method deleteBusinessGroupWithMail.
@Override
public MailerResult deleteBusinessGroupWithMail(BusinessGroup businessGroupTodelete, String businessPath, Identity deletedBy, Locale locale) {
List<Identity> users = businessGroupRelationDAO.getMembers(businessGroupTodelete, GroupRoles.coach.name(), GroupRoles.participant.name(), GroupRoles.waiting.name());
// now delete the group first
deleteBusinessGroup(businessGroupTodelete);
dbInstance.commit();
// finally send email
MailTemplate mailTemplate = BGMailHelper.createDeleteGroupMailTemplate(businessGroupTodelete, deletedBy);
if (mailTemplate != null) {
String metaId = UUID.randomUUID().toString();
MailContext context = new MailContextImpl(businessPath);
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, users, mailTemplate, null, metaId, result);
result.append(mailManager.sendMessage(bundles));
return result;
}
return null;
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class ContactFormController method doSend.
private void doSend(UserRequest ureq) {
MailerResult result;
try {
File[] attachments = cntctForm.getAttachments();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
if (emailFrom == null) {
// in case the user provides his own email in form
bundle.setFrom(cntctForm.getEmailFrom());
} else {
bundle.setFromId(emailFrom);
}
bundle.setContactLists(cntctForm.getEmailToContactLists());
bundle.setContent(cntctForm.getSubject(), cntctForm.getBody(), attachments);
result = mailService.sendMessage(bundle);
if (cntctForm.isTcpFrom()) {
MailBundle ccBundle = new MailBundle();
ccBundle.setContext(context);
if (emailFrom == null) {
// in case the user provides his own email in form
ccBundle.setFrom(cntctForm.getEmailFrom());
ccBundle.setTo(cntctForm.getEmailFrom());
} else {
ccBundle.setFromId(emailFrom);
ccBundle.setCc(emailFrom);
}
ccBundle.setContent(cntctForm.getSubject(), cntctForm.getBody(), attachments);
MailerResult ccResult = mailService.sendMessage(ccBundle);
result.append(ccResult);
}
if (result != null) {
if (result.isSuccessful()) {
showInfo("msg.send.ok");
// do logging
ThreadLocalUserActivityLogger.log(MailLoggingAction.MAIL_SENT, getClass());
fireEvent(ureq, Event.DONE_EVENT);
} else {
showError(ureq, result);
fireEvent(ureq, Event.FAILED_EVENT);
}
}
} catch (Exception e) {
logError("", e);
showWarning("error.msg.send.nok");
}
cntctForm.setDisplayOnly(true);
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class LectureServiceImpl method sendReminder.
private void sendReminder(Identity teacher, LectureBlock lectureBlock) {
RepositoryEntry entry = lectureBlock.getEntry();
String language = teacher.getUser().getPreferences().getLanguage();
Locale locale = i18nManager.getLocaleOrDefault(language);
String startDate = Formatter.getInstance(locale).formatDate(lectureBlock.getStartDate());
MailContext context = new MailContextImpl("[RepositoryEntry:" + entry.getKey() + "]");
String url = Settings.getServerContextPathURI() + "/url/RepositoryEntry/" + entry.getKey() + "/LectureBlock/" + lectureBlock.getKey();
String[] args = new String[] { // {0}
lectureBlock.getTitle(), // {1}
startDate, // {2}
entry.getDisplayname(), // {3}
url, // {4}
userManager.getUserDisplayName(teacher) };
Translator trans = Util.createPackageTranslator(LectureAdminController.class, locale);
String subject = trans.translate("lecture.teacher.reminder.subject", args);
String body = trans.translate("lecture.teacher.reminder.body", args);
LectureReminderTemplate template = new LectureReminderTemplate(subject, body);
MailerResult result = new MailerResult();
MailBundle bundle = mailManager.makeMailBundle(context, teacher, template, null, null, result);
MailerResult sendResult = mailManager.sendMessage(bundle);
result.append(sendResult);
String status;
List<Identity> failedIdentities = result.getFailedIdentites();
if (failedIdentities != null && failedIdentities.contains(teacher)) {
status = "error";
} else {
status = "ok";
}
lectureBlockReminderDao.createReminder(lectureBlock, teacher, status);
}
use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.
the class GTAParticipantController method doSubmissionEmail.
private void doSubmissionEmail() {
String body = config.getStringValue(GTACourseNode.GTASK_SUBMISSION_TEXT);
if (StringHelper.containsNonWhitespace(body)) {
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
List<Identity> recipientsTO;
File submitDirectory;
if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
recipientsTO = businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());
submitDirectory = gtaManager.getSubmitDirectory(courseEnv, gtaNode, assessedGroup);
} else {
recipientsTO = Collections.singletonList(assessedIdentity);
submitDirectory = gtaManager.getSubmitDirectory(courseEnv, gtaNode, assessedIdentity);
}
String subject = translate("submission.mail.subject");
File[] files = TaskHelper.getDocuments(submitDirectory);
MailTemplate template = new GTAMailTemplate(subject, body, files, getIdentity(), getTranslator());
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, recipientsTO, template, null, UUID.randomUUID().toString(), result);
mailManager.sendMessage(bundles);
}
}
Aggregations