use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class NotificationsManagerImpl method sendEmail.
private boolean sendEmail(Identity to, Translator translator, List<SubscriptionItem> subItems) {
String title = translator.translate("rss.title", new String[] { NotificationHelper.getFormatedName(to) });
StringBuilder htmlText = new StringBuilder();
htmlText.append("<style>");
htmlText.append(".o_m_sub h4 {margin: 0 0 10px 0;}");
htmlText.append(".o_m_sub ul {padding: 0 0 5px 20px; margin: 0;}");
htmlText.append(".o_m_sub ul li {padding: 0; margin: 1px 0;}");
htmlText.append(".o_m_go {padding: 5px 0 0 0}");
htmlText.append(".o_date {font-size: 90%; color: #888}");
htmlText.append(".o_m_footer {background: #FAFAFA; border: 1px solid #eee; border-radius: 5px; padding: 0 0.5em 0.5em 0.5em; margin: 1em 0 1em 0;' class='o_m_h'}");
htmlText.append("</style>");
for (Iterator<SubscriptionItem> it_subs = subItems.iterator(); it_subs.hasNext(); ) {
SubscriptionItem subitem = it_subs.next();
// o_m_wrap class for overriding styles in master mail template
htmlText.append("<div class='o_m_wrap'>");
// add background here for gmail as they ignore classes.
htmlText.append("<div class='o_m_sub' style='background: #FAFAFA; padding: 5px 5px; margin: 10px 0;'>");
// 1: title
htmlText.append(subitem.getTitle());
htmlText.append("\n");
// 2: content
String desc = subitem.getDescription();
if (StringHelper.containsNonWhitespace(desc)) {
htmlText.append(desc);
}
// 3: goto-link
String link = subitem.getLink();
if (StringHelper.containsNonWhitespace(link)) {
htmlText.append("<div class='o_m_go'><a href=\"").append(link).append("\">");
SubscriptionInfo subscriptionInfo = subitem.getSubsInfo();
if (subscriptionInfo != null) {
String innerType = subscriptionInfo.getType();
String typeName = NewControllerFactory.translateResourceableTypeName(innerType, translator.getLocale());
String open = translator.translate("resource.open", new String[] { typeName });
htmlText.append(open);
htmlText.append(" »</a></div>");
}
}
htmlText.append("\n");
htmlText.append("</div></div>");
}
String basePath = Settings.getServerContextPathURI() + "/auth/HomeSite/" + to.getKey() + "/";
htmlText.append("<div class='o_m_footer'>");
htmlText.append(translator.translate("footer.notifications", new String[] { basePath + "mysettings/0", basePath += "notifications/0", basePath + "/tab/1" }));
htmlText.append("</div>");
MailerResult result = null;
try {
MailBundle bundle = new MailBundle();
bundle.setToId(to);
bundle.setContent(title, htmlText.toString());
result = CoreSpringFactory.getImpl(MailManager.class).sendExternMessage(bundle, null, true);
} catch (Exception e) {
// FXOLAT-294 :: sending the mail will throw nullpointer exception if To-Identity has no
// valid email-address!, catch it...
}
if (result == null || result.getReturnCode() > 0) {
if (result != null)
log.warn("Could not send email to identity " + to.getName() + ". (returncode=" + result.getReturnCode() + ", to=" + to + ")");
else
log.warn("Could not send email to identity " + to.getName() + ". (returncode = null) , to=" + to + ")");
return false;
} else {
return true;
}
}
use of org.olat.core.util.mail.MailBundle 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;
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class BulkAssessmentTask method sendFeedback.
private void sendFeedback(List<BulkAssessmentFeedback> feedbacks) {
if (task == null) {
log.error("Haven't a task to know creator and modifiers of the task", null);
return;
}
Identity creator = task.getCreator();
String language = creator.getUser().getPreferences().getLanguage();
Locale locale = I18nManager.getInstance().getLocaleOrDefault(language);
Translator translator = Util.createPackageTranslator(BulkAssessmentOverviewController.class, locale, Util.createPackageTranslator(AssessmentManager.class, locale));
MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
TaskExecutorManager taskManager = CoreSpringFactory.getImpl(TaskExecutorManager.class);
String feedbackStr = renderFeedback(feedbacks, translator);
MailBundle mail = new MailBundle();
mail.setToId(creator);
mail.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
List<Identity> modifiers = taskManager.getModifiers(task);
if (modifiers.size() > 0) {
ContactList cc = new ContactList("CC");
cc.addAllIdentites(modifiers);
mail.setContactList(cc);
}
String businessPath = "";
ICourse course = CourseFactory.loadCourse(courseRes);
CourseNode node = course.getRunStructure().getNode(courseNodeIdent);
String courseTitle = course.getCourseTitle();
String nodeTitle = node.getShortTitle();
String numOfAssessedIds = Integer.toString(datas == null ? 0 : datas.getRowsSize());
String date = Formatter.getInstance(locale).formatDateAndTime(new Date());
mail.setContext(new MailContextImpl(courseRes, courseNodeIdent, businessPath));
String subject = translator.translate("confirmation.mail.subject", new String[] { courseTitle, nodeTitle });
String body = translator.translate("confirmation.mail.body", new String[] { courseTitle, nodeTitle, feedbackStr, numOfAssessedIds, date });
mail.setContent(subject, body);
mailManager.sendMessage(mail);
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class LoginTableDataModel method sendMail.
/**
* Send the mail with informations: who deletes, when, list of deleted users
* list of not deleted users, reason for deletion
*/
public void sendMail() {
String recipient = WebappHelper.getMailConfig("mailDeleteUser");
if (recipient.equals("disabled")) {
return;
}
StringBuilder loginsFound = new StringBuilder();
for (String login : lstLoginsFound) {
loginsFound.append(login + "\n");
}
StringBuilder loginsNotfound = new StringBuilder();
for (String login : lstLoginsNotfound) {
loginsNotfound.append(login + "\n");
}
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
String[] bodyArgs = new String[] { getIdentity().getName(), loginsFound.toString(), loginsNotfound.toString(), reason, df.format(new Date()) };
ContactList cl = new ContactList(recipient);
cl.add(recipient);
cl.add(getIdentity());
try {
MailBundle bundle = new MailBundle();
bundle.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
bundle.setContent(translate("mail.subject"), translate("mail.body", bodyArgs));
bundle.setContactList(cl);
mailService.sendMessage(bundle);
} catch (Exception e) {
logError("Notificatoin mail for bulk deletion could not be sent", null);
}
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class GroupController method doRemoveIdentitiesFromGroup.
private void doRemoveIdentitiesFromGroup(UserRequest ureq, List<Identity> toBeRemoved, MailTemplate mailTemplate) {
fireEvent(ureq, new IdentitiesRemoveEvent(toBeRemoved));
identitiesTableModel.remove(toBeRemoved);
if (tableCtr != null) {
// can be null in the follwoing case.
// the user which does the removal is also in the list of toBeRemoved
// hence the fireEvent does trigger a disposal of a GroupController, which
// in turn nullifies the tableCtr... see also OLAT-3331
tableCtr.modelChanged();
}
// send the notification mail
if (mailTemplate != null) {
// means no sender in footer
Identity sender = null;
if (showSenderInRemovMailFooter) {
sender = ureq.getIdentity();
}
String metaId = UUID.randomUUID().toString();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, toBeRemoved, mailTemplate, sender, metaId, result);
result.append(mailManager.sendMessage(bundles));
if (mailTemplate.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(context, ureq.getIdentity(), mailTemplate, sender, metaId, result);
result.append(mailManager.sendMessage(ccBundle));
}
MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
}
}
Aggregations