use of org.olat.core.util.mail.MailContext 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.MailContext 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.MailContext 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);
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class SendMailController method formOK.
@Override
protected void formOK(UserRequest ureq) {
ContactList contactList = new ContactList("");
Collection<String> roleList = contactEl.getSelectedKeys();
String[] roles = roleList.toArray(new String[roleList.size()]);
List<Identity> identities = repositoryService.getMembers(repoEntries, RepositoryEntryRelationType.both, roles);
if (identities.isEmpty()) {
showWarning("error.contact.to.empty");
} else {
Set<Identity> deduplicates = new HashSet<>(identities);
contactList.addAllIdentites(deduplicates);
boolean success = false;
try {
File[] attachmentArr = getAttachments();
MailContext context = null;
if (repoEntries.size() == 1) {
context = new MailContextImpl("[RepositoryEntry:" + repoEntries.get(0).getKey() + "]");
}
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFromId(getIdentity());
bundle.setContactLists(Collections.singletonList(contactList));
bundle.setContent(subjectEl.getValue(), bodyEl.getValue(), attachmentArr);
MailerResult result = mailService.sendMessage(bundle);
if (copyFromEl.isAtLeastSelected(1)) {
MailBundle ccBundle = new MailBundle();
ccBundle.setContext(context);
ccBundle.setFromId(getIdentity());
ccBundle.setCc(getIdentity());
ccBundle.setContent(subjectEl.getValue(), bodyEl.getValue(), attachmentArr);
MailerResult ccResult = mailService.sendMessage(ccBundle);
result.append(ccResult);
}
success = result.isSuccessful();
} catch (Exception e) {
// error in recipient email address(es)
handleAddressException(success);
}
if (success) {
showInfo("msg.send.ok");
// do logging
ThreadLocalUserActivityLogger.log(MailLoggingAction.MAIL_SENT, getClass());
fireEvent(ureq, Event.DONE_EVENT);
} else {
showInfo("error.msg.send.nok");
fireEvent(ureq, Event.FAILED_EVENT);
}
}
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class RepositoryMailing method sendEmail.
public static void sendEmail(Identity ureqIdentity, Identity identity, RepositoryEntry re, Type type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
String email = identity.getUser().getProperty(UserConstants.EMAIL, null);
String emailAlt = identity.getUser().getProperty(UserConstants.INSTITUTIONALEMAIL, null);
if (!StringHelper.containsNonWhitespace(email) && !StringHelper.containsNonWhitespace(emailAlt)) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
RepositoryModule repositoryModule = CoreSpringFactory.getImpl(RepositoryModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!repositoryModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
template = getDefaultTemplate(type, re, ureqIdentity);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[RepositoryEntry:" + re.getKey() + "]");
}
String metaId = mailing == null ? null : mailing.getUuid();
MailerResult result = new MailerResult();
MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailManager.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
Aggregations