Search in sources :

Example 1 with MailContextImpl

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

the class BulkAssessmentTask method sendFeedback.

private void sendFeedback(List<BulkAssessmentFeedback> feedbacks) {
    if (task == null) {
        log.error("Haven't a task to know creator and modifiers of the task", null);
        return;
    }
    Identity creator = task.getCreator();
    String language = creator.getUser().getPreferences().getLanguage();
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(language);
    Translator translator = Util.createPackageTranslator(BulkAssessmentOverviewController.class, locale, Util.createPackageTranslator(AssessmentManager.class, locale));
    MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
    TaskExecutorManager taskManager = CoreSpringFactory.getImpl(TaskExecutorManager.class);
    String feedbackStr = renderFeedback(feedbacks, translator);
    MailBundle mail = new MailBundle();
    mail.setToId(creator);
    mail.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
    List<Identity> modifiers = taskManager.getModifiers(task);
    if (modifiers.size() > 0) {
        ContactList cc = new ContactList("CC");
        cc.addAllIdentites(modifiers);
        mail.setContactList(cc);
    }
    String businessPath = "";
    ICourse course = CourseFactory.loadCourse(courseRes);
    CourseNode node = course.getRunStructure().getNode(courseNodeIdent);
    String courseTitle = course.getCourseTitle();
    String nodeTitle = node.getShortTitle();
    String numOfAssessedIds = Integer.toString(datas == null ? 0 : datas.getRowsSize());
    String date = Formatter.getInstance(locale).formatDateAndTime(new Date());
    mail.setContext(new MailContextImpl(courseRes, courseNodeIdent, businessPath));
    String subject = translator.translate("confirmation.mail.subject", new String[] { courseTitle, nodeTitle });
    String body = translator.translate("confirmation.mail.body", new String[] { courseTitle, nodeTitle, feedbackStr, numOfAssessedIds, date });
    mail.setContent(subject, body);
    mailManager.sendMessage(mail);
}
Also used : Locale(java.util.Locale) TaskExecutorManager(org.olat.core.commons.services.taskexecutor.TaskExecutorManager) MailContextImpl(org.olat.core.util.mail.MailContextImpl) AssessmentManager(org.olat.course.assessment.AssessmentManager) ICourse(org.olat.course.ICourse) ContactList(org.olat.core.util.mail.ContactList) Date(java.util.Date) Translator(org.olat.core.gui.translator.Translator) MailManager(org.olat.core.util.mail.MailManager) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) MSCourseNode(org.olat.course.nodes.MSCourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) ProjectBrokerCourseNode(org.olat.course.nodes.ProjectBrokerCourseNode) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 2 with MailContextImpl

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());
    }
}
Also used : 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 3 with MailContextImpl

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

the class InfoMessageFrontendManagerImpl method sendInfoMessage.

@Override
public boolean sendInfoMessage(InfoMessage infoMessage, MailFormatter mailFormatter, Locale locale, Identity from, List<Identity> tos) {
    infoMessageManager.saveInfoMessage(infoMessage);
    boolean send = false;
    if (tos != null && !tos.isEmpty()) {
        Set<Long> identityKeySet = new HashSet<Long>();
        ContactList contactList = new ContactList("Infos");
        for (Identity to : tos) {
            if (identityKeySet.contains(to.getKey()))
                continue;
            contactList.add(to);
            identityKeySet.add(to.getKey());
        }
        try {
            String subject = null;
            String body = null;
            if (mailFormatter != null) {
                subject = mailFormatter.getSubject(infoMessage);
                body = mailFormatter.getBody(infoMessage);
            }
            if (!StringHelper.containsNonWhitespace(subject)) {
                subject = infoMessage.getTitle();
            }
            if (!StringHelper.containsNonWhitespace(body)) {
                body = infoMessage.getMessage();
            }
            File attachment = null;
            if (StringHelper.containsNonWhitespace(infoMessage.getAttachmentPath())) {
                File root = getStoragePath().getBasefile();
                attachment = new File(root, infoMessage.getAttachmentPath());
            }
            MailContext context = new MailContextImpl(mailFormatter.getBusinessPath());
            MailBundle bundle = new MailBundle();
            bundle.setContext(context);
            bundle.setFromId(from);
            bundle.setContactList(contactList);
            if (attachment != null) {
                bundle.setContent(subject, body, attachment);
            } else {
                bundle.setContent(subject, body);
            }
            MailerResult result = mailManager.sendMessage(bundle);
            send = result.isSuccessful();
        } catch (Exception e) {
            log.error("Cannot send info messages", e);
        }
    }
    infoSubscriptionManager.markPublisherNews(infoMessage.getOLATResourceable(), infoMessage.getResSubPath());
    MultiUserEvent mue = new MultiUserEvent("new_info_message");
    coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(mue, oresFrontend);
    return send;
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) ContactList(org.olat.core.util.mail.ContactList) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) HashSet(java.util.HashSet)

Example 4 with MailContextImpl

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

the class MembersMailController method doSendEmailToMember.

private void doSendEmailToMember(UserRequest ureq, ContactList contactList) {
    boolean success = false;
    try {
        File[] attachmentArr = getAttachments();
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        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);
    }
}
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 5 with MailContextImpl

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

the class GTAAvailableTaskController method doSendConfirmationEmail.

private void doSendConfirmationEmail(Task assignedTask) {
    MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
    MailBundle bundle = new MailBundle();
    bundle.setContext(context);
    ContactList contacts = new ContactList("participants");
    if (GTAType.group.name().equals(gtaNode.getModuleConfiguration().getStringValue(GTACourseNode.GTASK_TYPE))) {
        List<Identity> participants = businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());
        contacts.addAllIdentites(participants);
        bundle.setMetaId(UUID.randomUUID().toString());
    } else {
        contacts.add(assessedIdentity);
    }
    bundle.setContactList(contacts);
    String[] args = new String[] { // 0 first name
    getIdentity().getUser().getFirstName(), // 1 last name
    getIdentity().getUser().getLastName(), // 2 course name
    courseEnv.getCourseTitle(), // 3 task
    assignedTask.getTaskName() };
    String subject = translate("mail.confirm.assignment.subject", args);
    String body = translate("mail.confirm.assignment.body", args);
    bundle.setContent(subject, body);
    mailManager.sendMessage(bundle);
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) ContactList(org.olat.core.util.mail.ContactList) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity)

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