use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class CourseCreationMailHelper method sentNotificationMail.
/**
* Sent notification mail for signalling that course creation was successful.
*
* @param ureq user request
* @param config course configuration object
* @return mailer result object
*/
public static final MailerResult sentNotificationMail(final UserRequest ureq, final CourseCreationConfiguration config) {
Translator translator = Util.createPackageTranslator(CourseCreationMailHelper.class, ureq.getLocale());
log.info("Course creation with wizard finished. [User: " + ureq.getIdentity().getName() + "] [Course name: " + config.getCourseTitle() + "]");
String subject = translator.translate("mail.subject", new String[] { config.getCourseTitle() });
String body = translator.translate("mail.body.0", new String[] { config.getCourseTitle() });
body += translator.translate("mail.body.1");
body += translator.translate("mail.body.2", new String[] { config.getExtLink() });
body += translator.translate("mail.body.3");
body += translator.translate("mail.body.4");
int counter = 1;
if (config.isCreateSinglePage()) {
body += translator.translate("mail.body.4.2", new String[] { Integer.toString(++counter) });
}
if (config.isCreateEnrollment()) {
body += translator.translate("mail.body.4.3", new String[] { Integer.toString(++counter) });
}
if (config.isCreateDownloadFolder()) {
body += translator.translate("mail.body.4.4", new String[] { Integer.toString(++counter) });
}
if (config.isCreateForum()) {
body += translator.translate("mail.body.4.5", new String[] { Integer.toString(++counter) });
}
if (config.isCreateContactForm()) {
body += translator.translate("mail.body.4.6", new String[] { Integer.toString(++counter) });
}
body += translator.translate("mail.body.5");
String url = CoreSpringFactory.getImpl(HelpModule.class).getHelpProvider().getURL(ureq.getLocale(), "");
body += translator.translate("mail.body.6", new String[] { url });
body += translator.translate("mail.body.greetings");
MailBundle bundle = new MailBundle();
bundle.setToId(ureq.getIdentity());
bundle.setContent(subject, body);
return CoreSpringFactory.getImpl(MailManager.class).sendExternMessage(bundle, null, false);
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class DENManageParticipantsController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == tableListParticipants) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent tableEvent = (TableEvent) event;
// open window for choosen date to manage the enrolled users or manually add
if (tableEvent.getActionId().equals(DENListTableDataModel.CHANGE_ACTION)) {
selectedEvent = listTableData.getObject(tableEvent.getRowId());
List<Identity> participants = denManager.getEventParticipants(selectedEvent);
participantsTableData = new DENParticipantsTableDataModel(participants);
removeAsListenerAndDispose(tableManageParticipants);
tableManageParticipants = denManager.createParticipantsTable(ureq, getWindowControl(), getTranslator(), participantsTableData);
listenTo(tableManageParticipants);
participantsVC = createVelocityContainer("participants");
DateFormat df = new SimpleDateFormat();
participantsVC.contextPut("dateTitle", selectedEvent.getSubject());
participantsVC.contextPut("dateTimeframe", df.format(selectedEvent.getBegin()) + " - " + df.format(selectedEvent.getEnd()));
participantsVC.put("participantsTable", tableManageParticipants.getInitialComponent());
addParticipantButton = LinkFactory.createButton("participants.add", participantsVC, this);
removeAsListenerAndDispose(manageParticipantsModalCntrl);
manageParticipantsModalCntrl = new CloseableModalController(getWindowControl(), "close", participantsVC, true, translate("dates.table.participant.manage"));
listenTo(manageParticipantsModalCntrl);
manageParticipantsModalCntrl.activate();
}
} else {
TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
BitSet selection = tmse.getSelection();
// delete all users from the selected dates
if (tmse.getAction().equals(DENListTableDataModel.DELETE_ACTION) && selection.cardinality() > 0) {
selectedIds = denManager.getSelectedEventParticipants(dateList, selection);
dateList = denManager.deleteParticipants(ores, courseNode, denManager.getSelectedEventIDs(dateList, selection));
listTableData.setObjects(dateList);
// send notification mail
createNotificationMail(ureq, courseNode.getShortTitle(), REMOVE_ACTION);
} else if (tmse.getAction().equals(DENListTableDataModel.MAIL_ACTION) && selection.cardinality() > 0) {
// send email to all users from the selected dates
List<Identity> participants = denManager.getSelectedEventParticipants(dateList, selection);
createParticipantsMail(ureq, participants);
} else if (selection.cardinality() == 0) {
showWarning("participants.message.empty");
}
}
} else if (source == userSearchCntrl) {
if (event == Event.CANCELLED_EVENT) {
userSearchCMC.deactivate();
} else {
List<Identity> toAdd = null;
selectedIds = new ArrayList<Identity>();
if (event instanceof SingleIdentityChosenEvent) {
SingleIdentityChosenEvent singleEvent = (SingleIdentityChosenEvent) event;
Identity choosenIdentity = singleEvent.getChosenIdentity();
toAdd = new ArrayList<Identity>();
toAdd.add(choosenIdentity);
} else if (event instanceof MultiIdentityChosenEvent) {
MultiIdentityChosenEvent multiEvent = (MultiIdentityChosenEvent) event;
toAdd = multiEvent.getChosenIdentities();
}
boolean showMessage = false;
if (toAdd != null && toAdd.size() > 0) {
for (Identity identity : toAdd) {
status = denManager.doEnroll(identity, selectedEvent, ores, courseNode, true);
if (!status.isEnrolled() && status.getErrorMessage().equals(DENStatus.ERROR_ALREADY_ENROLLED))
showMessage = true;
else
selectedIds.add(identity);
}
if (showMessage)
showWarning("enrollment.warning.manual");
refreshTables();
}
userSearchCMC.deactivate();
if (selectedIds.size() > 0) {
// write notification mail
createNotificationMail(ureq, selectedEvent.getSubject(), ADD_ACTION);
}
}
} else if (source == tableManageParticipants) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent tableEvent = (TableEvent) event;
// delete single user from event
if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.REMOVE_ACTION)) {
Identity identity = participantsTableData.getEntryAt(tableEvent.getRowId());
status = denManager.cancelEnroll(identity, selectedEvent, ores);
if (!status.isCancelled())
showError();
else // send notification mail
{
selectedIds.clear();
selectedIds.add(identity);
createNotificationMail(ureq, selectedEvent.getSubject(), REMOVE_ACTION);
}
refreshTables();
// write email to single user
} else if (tableEvent.getActionId().equals(DENParticipantsTableDataModel.MAIL_ACTION)) {
List<Identity> participants = new ArrayList<Identity>();
participants.add(participantsTableData.getEntryAt(tableEvent.getRowId()));
createParticipantsMail(ureq, participants);
}
}
} else if (source == notificationCtr && event == Event.DONE_EVENT) {
if (notificationCtr.getMailTemplate() != null) {
Identity sender = ureq.getIdentity();
MailerResult result = new MailerResult();
String metaId = UUID.randomUUID().toString().replace("-", "");
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle[] bundles = mailManager.makeMailBundles(context, selectedIds, notificationCtr.getMailTemplate(), sender, metaId, result);
result.append(mailManager.sendMessage(bundles));
if (notificationCtr.getMailTemplate().getCpfrom()) {
MailBundle ccBundles = mailManager.makeMailBundle(context, sender, notificationCtr.getMailTemplate(), sender, metaId, result);
result.append(mailManager.sendMessage(ccBundles));
}
MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
}
notificationCmc.deactivate();
selectedIds.clear();
} else if (source == contactCtr) {
notificationCmc.deactivate();
}
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class GroupController method doAddIdentitiesToGroup.
/**
* Add users from the identites array to the group if they are not guest users
* and not already in the group
*
* @param ureq
* @param choosenIdentities
*/
private void doAddIdentitiesToGroup(UserRequest ureq, List<Identity> choosenIdentities, MailTemplate mailTemplate) {
// additional security check
if (!mayModifyMembers)
throw new AssertException("not allowed to add member!");
IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(choosenIdentities);
// process workflow to BusinessGroupManager via BusinessGroupEditController
fireEvent(ureq, identitiesAddedEvent);
if (!identitiesAddedEvent.getAddedIdentities().isEmpty()) {
// update table model
reloadData();
}
// build info message for identities which could be added.
StringBuilder infoMessage = new StringBuilder();
for (Identity identity : identitiesAddedEvent.getIdentitiesWithoutPermission()) {
infoMessage.append(translate("msg.isingroupanonymous", userManager.getUserDisplayName(identity))).append("<br />");
}
for (Identity identity : identitiesAddedEvent.getIdentitiesAlreadyInGroup()) {
infoMessage.append(translate("msg.subjectalreadyingroup", userManager.getUserDisplayName(identity))).append("<br />");
}
// send the notification mail fro added users
StringBuilder errorMessage = new StringBuilder();
if (mailTemplate != null) {
// means no sender in footer
Identity sender = null;
if (showSenderInAddMailFooter) {
sender = ureq.getIdentity();
}
String metaId = UUID.randomUUID().toString();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailerResult result = new MailerResult();
MailBundle[] bundles = mailManager.makeMailBundles(context, identitiesAddedEvent.getAddedIdentities(), 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.appendErrorsAndWarnings(result, errorMessage, infoMessage, ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
}
// report any errors on screen
if (infoMessage.length() > 0)
getWindowControl().setWarning(infoMessage.toString());
if (errorMessage.length() > 0)
getWindowControl().setError(errorMessage.toString());
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class ErrorFeedbackMailer method sendMail.
/**
* send email to olat support with user submitted error informaition
*
* @param request
*/
public void sendMail(HttpServletRequest request) {
String feedback = request.getParameter("textarea");
String errorNr = request.getParameter("fx_errnum");
String username = request.getParameter("username");
try {
if (StringHelper.containsNonWhitespace(username)) {
Identity ident = securityManager.findIdentityByName(username);
Collection<String> logFileEntries = LogFileParser.getErrorToday(errorNr, false);
StringBuilder out = new StringBuilder(2048);
out.append(feedback).append("\n------------------------------------------\n\n --- from user: ").append(username).append(" ---");
if (logFileEntries != null) {
for (Iterator<String> iter = logFileEntries.iterator(); iter.hasNext(); ) {
out.append(iter.next());
}
}
MailBundle bundle = new MailBundle();
bundle.setFromId(ident);
bundle.setTo(WebappHelper.getMailConfig("mailError"));
bundle.setContent("Feedback from Error Nr.: " + errorNr, out.toString());
mailManager.sendExternMessage(bundle, null, false);
} else {
log.error("Try to send a feedback without identity");
}
} catch (Exception e) {
handleException(request, e);
return;
}
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class SendTokenToUserForm method sendToken.
private void sendToken(UserRequest ureq, String text) {
// mailer configuration
// We allow creation of password token when user has no password so far or when he as an OpenOLAT Password.
// For other cases such as Shibboleth, LDAP, oAuth etc. we don't allow creation of token as this is most
// likely not a desired action.
List<Authentication> authentications = BaseSecurityManager.getInstance().getAuthentications(user);
boolean isOOpwdAllowed = (authentications.size() == 0);
for (Authentication authentication : authentications) {
if (authentication.getProvider().equals(BaseSecurityModule.getDefaultAuthProviderIdentifier())) {
isOOpwdAllowed = true;
}
}
if (!isOOpwdAllowed) {
showWarning("sendtoken.wrong.auth");
return;
}
Preferences prefs = user.getUser().getPreferences();
Locale locale = i18nManager.getLocaleOrDefault(prefs.getLanguage());
String emailAdress = user.getUser().getProperty(UserConstants.EMAIL, locale);
String ip = ureq.getHttpReq().getRemoteAddr();
TemporaryKey tk = registrationManager.createAndDeleteOldTemporaryKey(user.getKey(), emailAdress, ip, RegistrationManager.PW_CHANGE);
if (text.indexOf(dummyKey) < 0) {
showWarning("changeuserpwd.failed");
logWarn("Can not replace temporary registration token in change pwd mail token dialog, user probably changed temporary token in mai template", null);
return;
}
String body = text.replace(dummyKey, tk.getRegistrationKey());
Translator userTrans = Util.createPackageTranslator(RegistrationManager.class, locale);
MailBundle bundle = new MailBundle();
bundle.setToId(user);
bundle.setContent(userTrans.translate("pwchange.subject"), body);
MailerResult result = mailManager.sendExternMessage(bundle, null, false);
if (result.getReturnCode() == 0) {
showInfo("email.sent");
} else {
showInfo("email.notsent");
}
}
Aggregations