Search in sources :

Example 41 with MailContextImpl

use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.

the class IQEditReplaceWizard method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == mailCtr && event == Event.DONE_EVENT) {
        MailTemplate mailTemplate = mailCtr.getMailTemplate();
        if (mailTemplate != null) {
            MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
            String metaId = UUID.randomUUID().toString().replace("-", "");
            MailerResult result = new MailerResult();
            MailBundle[] bundles = mailManager.makeMailBundles(context, learners, mailTemplate, getIdentity(), metaId, result);
            result.append(mailManager.sendMessage(bundles));
            if (mailTemplate.getCpfrom()) {
                MailBundle ccBundle = mailManager.makeMailBundle(context, getIdentity(), mailTemplate, getIdentity(), metaId, result);
                result.append(mailManager.sendMessage(ccBundle));
            }
        }
        fireEvent(ureq, Event.DONE_EVENT);
    } else if (source == searchCtr && event == ReferencableEntriesSearchController.EVENT_REPOSITORY_ENTRY_SELECTED) {
        selectedRepositoryEntry = searchCtr.getSelectedEntry();
        doStep2(ureq);
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) MailTemplate(org.olat.core.util.mail.MailTemplate) MailBundle(org.olat.core.util.mail.MailBundle)

Example 42 with MailContextImpl

use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.

the class BGEmailCompositionStepController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    boolean success = false;
    try {
        File[] attachments = contactForm.getAttachments();
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        MailBundle bundle = new MailBundle();
        bundle.setContext(context);
        bundle.setFromId(getIdentity());
        bundle.setContactLists(contactForm.getEmailToContactLists());
        bundle.setContent(contactForm.getSubject(), contactForm.getBody(), attachments);
        MailerResult result = mailService.sendMessage(bundle);
        success = result.isSuccessful();
        if (contactForm.isTcpFrom()) {
            MailBundle ccBundle = new MailBundle();
            ccBundle.setContext(context);
            ccBundle.setFromId(getIdentity());
            ccBundle.setCc(getIdentity());
            ccBundle.setContent(contactForm.getSubject(), contactForm.getBody(), attachments);
            MailerResult ccResult = mailService.sendMessage(ccBundle);
            success = ccResult.isSuccessful();
        }
    } catch (Exception e) {
        logError(null, e);
    }
    if (success) {
        fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File)

Example 43 with MailContextImpl

use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.

the class OLATAuthManager method sendConfirmationEmail.

private void sendConfirmationEmail(Identity doer, Identity identity) {
    String prefsLanguage = identity.getUser().getPreferences().getLanguage();
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(prefsLanguage);
    Translator translator = Util.createPackageTranslator(OLATAuthenticationController.class, locale);
    ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(OresHelper.createOLATResourceableInstance("changepw", 0l));
    String changePwUrl = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
    String[] args = new String[] { // 0: changed users username
    identity.getName(), // 1: changed users email address
    UserManager.getInstance().getUserDisplayEmail(identity, locale), // 2: Name (first and last name) of user who changed the password
    userManager.getUserDisplayName(doer.getUser()), // 3: configured support email address
    WebappHelper.getMailConfig("mailSupport"), // 4: direct link to change password workflow (e.g. https://xx.xx.xx/olat/url/changepw/0)
    changePwUrl };
    String subject = translator.translate("mail.pwd.subject", args);
    String body = translator.translate("mail.pwd.body", args);
    MailContext context = new MailContextImpl(null, null, "[Identity:" + identity.getKey() + "]");
    MailBundle bundle = new MailBundle();
    bundle.setContext(context);
    bundle.setToId(identity);
    bundle.setContent(subject, body);
    mailManager.sendMessage(bundle);
}
Also used : Locale(java.util.Locale) MailContextImpl(org.olat.core.util.mail.MailContextImpl) Translator(org.olat.core.gui.translator.Translator) MailContext(org.olat.core.util.mail.MailContext) MailBundle(org.olat.core.util.mail.MailBundle) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 44 with MailContextImpl

use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.

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", "&#10;").replace("\r", "&#10;").replace("\u2028", "&#10;");
                        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", "&#10;").replace("\r", "&#10;").replace("\u2028", "&#10;");
                        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", "&#10;").replace("\r", "&#10;").replace("\u2028", "&#10;"));
                }
            } else {
                showInfo("dropbox.upload.failed");
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) MailManager(org.olat.core.util.mail.MailManager) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 45 with MailContextImpl

use of org.olat.core.util.mail.MailContextImpl in project openolat by klemens.

the class ReturnboxFullAccessCallback 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 == dropboxFolderRunController) {
        if (event instanceof FolderEvent) {
            FolderEvent folderEvent = (FolderEvent) event;
            if (folderEvent.getCommand().equals(FolderEvent.DELETE_EVENT)) {
                UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
                // log entry for this file
                Identity coach = ureq.getIdentity();
                Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
                am.appendToUserNodeLog(node, coach, student, "FILE DELETED: " + folderEvent.getFilename());
            }
        }
    } else if (source == returnboxFolderRunController) {
        if (event instanceof FolderEvent) {
            FolderEvent folderEvent = (FolderEvent) event;
            if (folderEvent.getCommand().equals(FolderEvent.UPLOAD_EVENT) || folderEvent.getCommand().equals(FolderEvent.NEW_FILE_EVENT)) {
                UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
                // log entry for this file
                Identity coach = ureq.getIdentity();
                Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
                if (node instanceof AssessableCourseNode) {
                    AssessableCourseNode acn = (AssessableCourseNode) node;
                    AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
                    if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
                        eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
                        acn.updateUserScoreEvaluation(eval, userCourseEnv, coach, false, Role.coach);
                    }
                }
                am.appendToUserNodeLog(node, coach, student, "FILE UPLOADED: " + folderEvent.getFilename());
                String toMail = UserManager.getInstance().getUserDisplayEmail(student, ureq.getLocale());
                OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseNode.class, Long.valueOf(node.getIdent()));
                ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
                BusinessControl bc = BusinessControlFactory.getInstance().createBusinessControl(ce, getWindowControl().getBusinessControl());
                String link = BusinessControlFactory.getInstance().getAsURIString(bc, true);
                log.debug("DEBUG : Returnbox notification email with link=" + link);
                String subject = translate("returnbox.email.subject");
                String body = translate("returnbox.email.body", new String[] { userCourseEnv.getCourseEnvironment().getCourseTitle(), node.getShortTitle(), folderEvent.getFilename(), link });
                MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
                MailBundle bundle = new MailBundle();
                bundle.setContext(context);
                bundle.setToId(student);
                bundle.setContent(subject, body);
                MailerResult result = CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
                if (result.getReturnCode() > 0) {
                    am.appendToUserNodeLog(node, coach, student, "MAIL SEND FAILED TO:" + toMail + "; MailReturnCode: " + result.getReturnCode());
                    log.warn("Could not send email 'returnbox notification' to " + student + "with email=" + toMail);
                } else {
                    log.info("Send email 'returnbox notification' to " + student + "with email=" + toMail);
                }
            }
        } else if (FolderCommand.FOLDERCOMMAND_FINISHED == event) {
            if (node instanceof AssessableCourseNode) {
                AssessableCourseNode acn = (AssessableCourseNode) node;
                AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
                if (eval == null) {
                    eval = AssessmentEvaluation.EMPTY_EVAL;
                }
                if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
                    eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
                    acn.updateUserScoreEvaluation(eval, userCourseEnv, getIdentity(), false, Role.coach);
                    fireEvent(ureq, Event.CHANGED_EVENT);
                }
            }
        }
    } else if (source == statusForm) {
        if (event == Event.DONE_EVENT) {
            // get identity not from request (this would be an author)
            StatusManager.getInstance().saveStatusFormData(statusForm, node, userCourseEnv);
        }
    } else if (source == dialogBoxController) {
        if (DialogBoxUIFactory.isYesEvent(event) && assignedTask != null) {
            // cancel task assignment, and show "no task assigned to user"
            removeAssignedTask(userCourseEnv, userCourseEnv.getIdentityEnvironment().getIdentity());
            // update UI
            myContent.contextPut("assignedtask", null);
        }
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) AssessmentEvaluation(org.olat.course.run.scoring.AssessmentEvaluation) OLATResourceable(org.olat.core.id.OLATResourceable) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) BusinessControl(org.olat.core.id.context.BusinessControl) ContextEntry(org.olat.core.id.context.ContextEntry) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Aggregations

MailBundle (org.olat.core.util.mail.MailBundle)72 MailContextImpl (org.olat.core.util.mail.MailContextImpl)72 MailContext (org.olat.core.util.mail.MailContext)70 MailerResult (org.olat.core.util.mail.MailerResult)66 Identity (org.olat.core.id.Identity)44 MailTemplate (org.olat.core.util.mail.MailTemplate)30 ContactList (org.olat.core.util.mail.ContactList)20 File (java.io.File)14 ArrayList (java.util.ArrayList)8 Locale (java.util.Locale)8 MailManager (org.olat.core.util.mail.MailManager)8 Translator (org.olat.core.gui.translator.Translator)7 Property (org.olat.properties.Property)7 ContextEntry (org.olat.core.id.context.ContextEntry)6 HashSet (java.util.HashSet)4 List (java.util.List)4 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)4 IdentitiesRemoveEvent (org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)4 AssertException (org.olat.core.logging.AssertException)4