Search in sources :

Example 6 with MailContext

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

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 7 with MailContext

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

the class ProjectBrokerMailerImpl method sendEmailProjectChanged.

private MailerResult sendEmailProjectChanged(List<Identity> group, Identity changer, Project project, String subject, String body, Locale locale) {
    MailTemplate enrolledMailTemplate = this.createProjectChangeMailTemplate(project, changer, subject, body, locale);
    // loop over all project manger
    StringBuilder identityNames = new StringBuilder();
    for (Identity identity : group) {
        if (identityNames.length() > 0)
            identityNames.append(",");
        identityNames.append(identity.getName());
    }
    MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
    MailerResult result = new MailerResult();
    MailBundle[] bundles = mailManager.makeMailBundles(context, group, enrolledMailTemplate, null, null, result);
    result.append(mailManager.sendMessage(bundles));
    log.audit("ProjectBroker: sendEmailToGroup: identities=" + identityNames.toString() + " , 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) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 8 with MailContext

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

the class ProjectBrokerMailerImpl method sendEmailToGroup.

private MailerResult sendEmailToGroup(List<Identity> group, Identity enrolledIdentity, Project project, String subject, String body, Locale locale) {
    MailTemplate enrolledMailTemplate = this.createMailTemplate(project, enrolledIdentity, subject, body, locale);
    // loop over all project manger
    StringBuilder identityNames = new StringBuilder();
    for (Identity identity : group) {
        if (identityNames.length() > 0)
            identityNames.append(",");
        identityNames.append(identity.getName());
    }
    MailContext context = new MailContextImpl(project.getProjectBroker(), null, null);
    String metaId = UUID.randomUUID().toString().replace("-", "");
    MailerResult result = new MailerResult();
    MailBundle[] bundles = mailManager.makeMailBundles(context, group, enrolledMailTemplate, null, metaId, result);
    result.append(mailManager.sendMessage(bundles));
    log.audit("ProjectBroker: sendEmailToGroup: identities=" + identityNames.toString() + " , 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) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 9 with MailContext

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

the class InvitationEditRightsController method sendInvitation.

private void sendInvitation() {
    String inviteeEmail = invitee.getUser().getProperty(UserConstants.EMAIL, getLocale());
    ContactList contactList = new ContactList(inviteeEmail);
    contactList.add(inviteeEmail);
    boolean success = false;
    try {
        mailTemplate.setSubjectTemplate(subjectEl.getValue());
        mailTemplate.setBodyTemplate(bodyEl.getValue());
        MailContext context = new MailContextImpl(binder, null, getWindowControl().getBusinessControl().getAsString());
        MailBundle bundle = new MailBundle();
        bundle.setContext(context);
        bundle.setFromId(getIdentity());
        bundle.setContactList(contactList);
        bundle.setContent(subjectEl.getValue(), bodyEl.getValue());
        MailerResult result = mailManager.sendExternMessage(bundle, null, true);
        success = result.isSuccessful();
    } catch (Exception e) {
        logError("Error on sending invitation mail to contactlist, invalid address.", e);
    }
    if (success) {
        showInfo("invitation.mail.success");
    } else {
        showError("invitation.mail.failure");
    }
}
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) MailBundle(org.olat.core.util.mail.MailBundle)

Example 10 with MailContext

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

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);
        }
    }
}
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) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle) File(java.io.File) HashSet(java.util.HashSet)

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