use of org.olat.core.util.mail.MailContextImpl 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());
}
}
use of org.olat.core.util.mail.MailContextImpl in project OpenOLAT by OpenOLAT.
the class FinishCallback method sendMail.
private boolean sendMail(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
boolean success = false;
try {
ContactList contacts = new ContactList("Forum");
ListWrapper recipients = (ListWrapper) runContext.get(SendMailStepForm.RECIPIENTS);
contacts.addAllIdentites(recipients.getListOfIdentity());
MailContext context = new MailContextImpl(wControl.getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
Identity sender = (Identity) runContext.get(SendMailStepForm.SENDER);
bundle.setFromId(sender != null ? sender : ureq.getIdentity());
bundle.setContactLists(new ArrayList<ContactList>(Arrays.asList(contacts)));
MailTemplate mailTemplate = (MailTemplate) runContext.get(SendMailStepForm.MAIL_TEMPLATE);
bundle.setContent(mailTemplate.getSubjectTemplate(), mailTemplate.getBodyTemplate());
MailerResult result = mailService.sendMessage(bundle);
return success = result.isSuccessful();
} catch (Exception e) {
log.error(null, e);
return success;
}
}
use of org.olat.core.util.mail.MailContextImpl in project OpenOLAT by OpenOLAT.
the class DropboxController 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 == fileChooserController) {
cmc.deactivate();
if (event.equals(Event.DONE_EVENT)) {
boolean success = false;
File fIn = fileChooserController.getUploadFile();
VFSContainer fDropbox = getDropBox(ureq.getIdentity());
String filename = fileChooserController.getUploadFileName();
VFSLeaf fOut;
if (fDropbox.resolve(filename) != null) {
// FIXME ms: check if dropbox quota is exceeded -> clarify with customers
fOut = fDropbox.createChildLeaf(getNewUniqueName(filename));
} else {
fOut = fDropbox.createChildLeaf(filename);
}
try {
InputStream in = new FileInputStream(fIn);
OutputStream out = new BufferedOutputStream(fOut.getOutputStream(false));
success = FileUtils.copy(in, out);
FileUtils.closeSafely(in);
FileUtils.closeSafely(out);
} catch (FileNotFoundException e) {
logError("", e);
return;
}
if (fOut instanceof MetaTagged) {
MetaInfo info = ((MetaTagged) fOut).getMetaInfo();
if (info != null) {
info.setAuthor(ureq.getIdentity());
info.write();
}
}
if (success) {
int numFiles = fDropbox.getItems().size();
myContent.contextPut("numfiles", new String[] { Integer.toString(numFiles) });
// assemble confirmation
String confirmation = getConfirmation(ureq, fOut.getName());
// send email if necessary
Boolean sendEmail = (Boolean) config.get(TACourseNode.CONF_DROPBOX_ENABLEMAIL);
if (sendEmail == null)
sendEmail = Boolean.FALSE;
boolean sendMailError = false;
if (sendEmail.booleanValue()) {
// send mail
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setToId(ureq.getIdentity());
bundle.setContent(translate("conf.mail.subject"), confirmation);
MailerResult result = CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
if (result.getFailedIdentites().size() > 0) {
List<Identity> disabledIdentities = new ArrayList<Identity>();
disabledIdentities = result.getFailedIdentites();
// show error that message can not be sent
ArrayList<String> myButtons = new ArrayList<String>();
myButtons.add(translate("back"));
String title = MailHelper.getTitleForFailedUsersError(ureq.getLocale());
String message = MailHelper.getMessageForFailedUsersError(ureq.getLocale(), disabledIdentities);
// add dropbox specific error message
message += "\n<br />" + translate("conf.mail.error");
// FIXME:FG:6.2: fix problem in info message, not here
message += "\n<br />\n<br />" + confirmation.replace("\n", " ").replace("\r", " ").replace("\u2028", " ");
DialogBoxController noUsersErrorCtr = null;
noUsersErrorCtr = activateGenericDialog(ureq, title, message, myButtons, noUsersErrorCtr);
sendMailError = true;
} else if (result.getReturnCode() > 0) {
// show error that message can not be sent
ArrayList<String> myButtons = new ArrayList<String>();
myButtons.add(translate("back"));
DialogBoxController noUsersErrorCtr = null;
String message = translate("conf.mail.error");
// FIXME:FG:6.2: fix problem in info message, not here
message += "\n<br />\n<br />" + confirmation.replace("\n", " ").replace("\r", " ").replace("\u2028", " ");
noUsersErrorCtr = activateGenericDialog(ureq, translate("error.header"), message, myButtons, noUsersErrorCtr);
sendMailError = true;
}
}
// inform subscription manager about new element
if (subsContext != null) {
NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
}
// FIXME:FG:6.2: fix problem in info message, not here
if (!sendMailError) {
getWindowControl().setInfo(confirmation.replace("\n", " ").replace("\r", " ").replace("\u2028", " "));
}
} else {
showInfo("dropbox.upload.failed");
}
}
}
}
use of org.olat.core.util.mail.MailContextImpl in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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);
}
Aggregations