Search in sources :

Example 66 with MailContext

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

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)

Example 67 with MailContext

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

the class ProjectGroupController method handleCandidateGroupEvent.

private void handleCandidateGroupEvent(UserRequest urequest, Event event) {
    if (event instanceof IdentitiesAddEvent) {
        IdentitiesAddEvent identitiesAddEvent = (IdentitiesAddEvent) event;
        List<Identity> addedIdentities = projectGroupManager.addCandidates(identitiesAddEvent.getAddIdentities(), project);
        identitiesAddEvent.setIdentitiesAddedEvent(addedIdentities);
        fireEvent(urequest, Event.CHANGED_EVENT);
    } else if (event instanceof IdentitiesRemoveEvent) {
        projectGroupManager.removeCandidates(((IdentitiesRemoveEvent) event).getRemovedIdentities(), project);
        fireEvent(urequest, Event.CHANGED_EVENT);
    } else if (event instanceof IdentitiesMoveEvent) {
        final IdentitiesMoveEvent identitiesMoveEvent = (IdentitiesMoveEvent) event;
        // OLAT-6342: check identity not in group first!
        List<Identity> moveIdents = identitiesMoveEvent.getChosenIdentities();
        BusinessGroupAddResponse response = projectGroupManager.acceptCandidates(moveIdents, project, urequest.getIdentity(), projectBrokerModuleConfiguration.isAutoSignOut(), projectBrokerModuleConfiguration.isAcceptSelectionManually());
        identitiesMoveEvent.setMovedIdentities(response.getAddedIdentities());
        identitiesMoveEvent.setNotMovedIdentities(response.getIdentitiesAlreadyInGroup());
        // send mail for all of them
        MailTemplate mailTemplate = identitiesMoveEvent.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, identitiesMoveEvent.getMovedIdentities(), mailTemplate, null, metaId, result);
            result.append(mailManager.sendMessage(bundles));
            if (mailTemplate.getCpfrom()) {
                MailBundle ccBundle = mailManager.makeMailBundle(context, urequest.getIdentity(), mailTemplate, null, metaId, result);
                result.append(mailManager.sendMessage(ccBundle));
            }
            MailHelper.printErrorsAndWarnings(result, getWindowControl(), urequest.getUserSession().getRoles().isOLATAdmin(), urequest.getLocale());
        }
        fireEvent(urequest, Event.CHANGED_EVENT);
        // Participant and waiting-list were changed => reload both
        projectMemberController.reloadData();
        // Do only reload data in case of IdentitiesMoveEvent (IdentitiesAddEvent and reload data resulting in doublicate values)
        projectCandidatesController.reloadData();
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) IdentitiesRemoveEvent(org.olat.admin.securitygroup.gui.IdentitiesRemoveEvent) MailTemplate(org.olat.core.util.mail.MailTemplate) IdentitiesAddEvent(org.olat.admin.securitygroup.gui.IdentitiesAddEvent) BusinessGroupAddResponse(org.olat.group.BusinessGroupAddResponse) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) IdentitiesMoveEvent(org.olat.admin.securitygroup.gui.IdentitiesMoveEvent)

Example 68 with MailContext

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

the class ProjectBrokerMailerImpl method sendEmail.

// ////////////////
// Private Methods
// ////////////////
private MailerResult sendEmail(Identity enrolledIdentity, Project project, String subject, String body, Locale locale) {
    MailTemplate enrolledMailTemplate = createMailTemplate(project, enrolledIdentity, subject, body, locale);
    MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
    MailerResult result = new MailerResult();
    MailBundle bundle = mailManager.makeMailBundle(context, enrolledIdentity, enrolledMailTemplate, null, null, result);
    if (bundle != null) {
        mailManager.sendMessage(bundle);
    }
    log.audit("ProjectBroker: sendEmail to identity.name=" + enrolledIdentity.getName() + " , mailerResult.returnCode=" + result.getReturnCode());
    return result;
}
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 69 with MailContext

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

the class TaskFolderCallback method sendNotificationEmail.

private void sendNotificationEmail(UserRequest ureq, MailTemplate mailTemplate, List<Identity> recipients) {
    // send the notification mail
    if (mailTemplate != null) {
        Identity sender = ureq.getIdentity();
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        MailerResult result = new MailerResult();
        String metaId = UUID.randomUUID().toString().replace("-", "");
        MailBundle[] bundles = mailManager.makeMailBundles(context, recipients, mailTemplate, sender, metaId, result);
        result.append(mailManager.sendMessage(bundles));
        if (mailTemplate.getCpfrom()) {
            MailBundle ccBundle = mailManager.makeMailBundle(context, sender, 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 70 with MailContext

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

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)

Aggregations

MailBundle (org.olat.core.util.mail.MailBundle)70 MailContext (org.olat.core.util.mail.MailContext)70 MailContextImpl (org.olat.core.util.mail.MailContextImpl)70 MailerResult (org.olat.core.util.mail.MailerResult)66 Identity (org.olat.core.id.Identity)42 MailTemplate (org.olat.core.util.mail.MailTemplate)30 ContactList (org.olat.core.util.mail.ContactList)18 File (java.io.File)14 ArrayList (java.util.ArrayList)8 Property (org.olat.properties.Property)7 Locale (java.util.Locale)6 ContextEntry (org.olat.core.id.context.ContextEntry)6 MailManager (org.olat.core.util.mail.MailManager)6 Translator (org.olat.core.gui.translator.Translator)5 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