Search in sources :

Example 96 with MailBundle

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());
    }
}
Also used : IdentitiesRemoveEvent(org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent) MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 97 with MailBundle

use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.

the class AssessmentEntryOutcomesListener method decorateResourceConfirmation.

public static void decorateResourceConfirmation(RepositoryEntry entry, RepositoryEntry testEntry, AssessmentTestSession candidateSession, DigitalSignatureOptions options, Date timestamp, Locale locale) {
    MailBundle bundle = new MailBundle();
    bundle.setToId(candidateSession.getIdentity());
    Identity assessedIdentity = candidateSession.getIdentity();
    String fullname = CoreSpringFactory.getImpl(UserManager.class).getUserDisplayName(assessedIdentity);
    Date assessedDate = candidateSession.getFinishTime() == null ? timestamp : candidateSession.getFinishTime();
    Translator translator = Util.createPackageTranslator(QTI21RuntimeController.class, locale);
    String[] args = new String[] { // {0}
    entry.getDisplayname(), // {1}
    entry.getKey().toString(), // {2}
    "", // {3}
    "", // {4}
    testEntry.getDisplayname(), // {5}
    fullname, Formatter.getInstance(locale).formatDateAndTime(// {6}
    assessedDate), // {7}
    assessedIdentity.getName(), assessedIdentity.getUser().getProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, // {8}
    locale), assessedIdentity.getUser().getProperty(UserConstants.INSTITUTIONALNAME, // {9}
    locale) };
    String subject = translator.translate("digital.signature.mail.subject", args);
    String body = translator.translate("digital.signature.mail.body", args);
    bundle.setContent(subject, body);
    options.setMailBundle(bundle);
}
Also used : Translator(org.olat.core.gui.translator.Translator) UserManager(org.olat.user.UserManager) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 98 with MailBundle

use of org.olat.core.util.mail.MailBundle 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;
    }
}
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) ContactList(org.olat.core.util.mail.ContactList) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity)

Example 99 with MailBundle

use of org.olat.core.util.mail.MailBundle 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", "&#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 100 with MailBundle

use of org.olat.core.util.mail.MailBundle 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);
}
Also used : Locale(java.util.Locale) MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) Translator(org.olat.core.gui.translator.Translator) MailerResult(org.olat.core.util.mail.MailerResult) RepositoryEntry(org.olat.repository.RepositoryEntry) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity)

Aggregations

MailBundle (org.olat.core.util.mail.MailBundle)126 MailerResult (org.olat.core.util.mail.MailerResult)100 Identity (org.olat.core.id.Identity)72 MailContextImpl (org.olat.core.util.mail.MailContextImpl)72 MailContext (org.olat.core.util.mail.MailContext)70 MailTemplate (org.olat.core.util.mail.MailTemplate)32 Translator (org.olat.core.gui.translator.Translator)28 ContactList (org.olat.core.util.mail.ContactList)28 Locale (java.util.Locale)20 File (java.io.File)18 Date (java.util.Date)16 Test (org.junit.Test)14 MailManager (org.olat.core.util.mail.MailManager)14 DBMailLight (org.olat.core.util.mail.model.DBMailLight)12 ArrayList (java.util.ArrayList)10 Property (org.olat.properties.Property)7 ContextEntry (org.olat.core.id.context.ContextEntry)6 AssertException (org.olat.core.logging.AssertException)6 TemporaryKey (org.olat.registration.TemporaryKey)6 UserManager (org.olat.user.UserManager)6