Search in sources :

Example 96 with MailerResult

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

the class GroupController method doAddIdentitiesToGroup.

/**
 * Add users from the identites array to the group if they are not guest users
 * and not already in the group
 *
 * @param ureq
 * @param choosenIdentities
 */
private void doAddIdentitiesToGroup(UserRequest ureq, List<Identity> choosenIdentities, MailTemplate mailTemplate) {
    // additional security check
    if (!mayModifyMembers)
        throw new AssertException("not allowed to add member!");
    IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(choosenIdentities);
    // process workflow to BusinessGroupManager via BusinessGroupEditController
    fireEvent(ureq, identitiesAddedEvent);
    if (!identitiesAddedEvent.getAddedIdentities().isEmpty()) {
        // update table model
        reloadData();
    }
    // build info message for identities which could be added.
    StringBuilder infoMessage = new StringBuilder();
    for (Identity identity : identitiesAddedEvent.getIdentitiesWithoutPermission()) {
        infoMessage.append(translate("msg.isingroupanonymous", userManager.getUserDisplayName(identity))).append("<br />");
    }
    for (Identity identity : identitiesAddedEvent.getIdentitiesAlreadyInGroup()) {
        infoMessage.append(translate("msg.subjectalreadyingroup", userManager.getUserDisplayName(identity))).append("<br />");
    }
    // send the notification mail fro added users
    StringBuilder errorMessage = new StringBuilder();
    if (mailTemplate != null) {
        // means no sender in footer
        Identity sender = null;
        if (showSenderInAddMailFooter) {
            sender = ureq.getIdentity();
        }
        String metaId = UUID.randomUUID().toString();
        MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
        MailerResult result = new MailerResult();
        MailBundle[] bundles = mailManager.makeMailBundles(context, identitiesAddedEvent.getAddedIdentities(), 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.appendErrorsAndWarnings(result, errorMessage, infoMessage, ureq.getUserSession().getRoles().isOLATAdmin(), ureq.getLocale());
    }
    // report any errors on screen
    if (infoMessage.length() > 0)
        getWindowControl().setWarning(infoMessage.toString());
    if (errorMessage.length() > 0)
        getWindowControl().setError(errorMessage.toString());
}
Also used : AssertException(org.olat.core.logging.AssertException) 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 MailerResult

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

the class SendTokenToUserForm method sendToken.

private void sendToken(UserRequest ureq, String text) {
    // mailer configuration
    // We allow creation of password token when user has no password so far or when he as an OpenOLAT Password.
    // For other cases such as Shibboleth, LDAP, oAuth etc. we don't allow creation of token as this is most
    // likely not a desired action.
    List<Authentication> authentications = BaseSecurityManager.getInstance().getAuthentications(user);
    boolean isOOpwdAllowed = (authentications.size() == 0);
    for (Authentication authentication : authentications) {
        if (authentication.getProvider().equals(BaseSecurityModule.getDefaultAuthProviderIdentifier())) {
            isOOpwdAllowed = true;
        }
    }
    if (!isOOpwdAllowed) {
        showWarning("sendtoken.wrong.auth");
        return;
    }
    Preferences prefs = user.getUser().getPreferences();
    Locale locale = i18nManager.getLocaleOrDefault(prefs.getLanguage());
    String emailAdress = user.getUser().getProperty(UserConstants.EMAIL, locale);
    String ip = ureq.getHttpReq().getRemoteAddr();
    TemporaryKey tk = registrationManager.createAndDeleteOldTemporaryKey(user.getKey(), emailAdress, ip, RegistrationManager.PW_CHANGE);
    if (text.indexOf(dummyKey) < 0) {
        showWarning("changeuserpwd.failed");
        logWarn("Can not replace temporary registration token in change pwd mail token dialog, user probably changed temporary token in mai template", null);
        return;
    }
    String body = text.replace(dummyKey, tk.getRegistrationKey());
    Translator userTrans = Util.createPackageTranslator(RegistrationManager.class, locale);
    MailBundle bundle = new MailBundle();
    bundle.setToId(user);
    bundle.setContent(userTrans.translate("pwchange.subject"), body);
    MailerResult result = mailManager.sendExternMessage(bundle, null, false);
    if (result.getReturnCode() == 0) {
        showInfo("email.sent");
    } else {
        showInfo("email.notsent");
    }
}
Also used : Locale(java.util.Locale) Translator(org.olat.core.gui.translator.Translator) MailerResult(org.olat.core.util.mail.MailerResult) Authentication(org.olat.basesecurity.Authentication) TemporaryKey(org.olat.registration.TemporaryKey) Preferences(org.olat.core.id.Preferences) MailBundle(org.olat.core.util.mail.MailBundle)

Example 98 with MailerResult

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

the class CourseOverviewController method doAddToRepositoryEntry.

private void doAddToRepositoryEntry(UserRequest ureq, Collection<RepositoryEntry> res, SearchType type, boolean sendEmail) {
    // commit changes to the repository entry
    MailerResult result = new MailerResult();
    MailPackage reMailing = new MailPackage(result, getWindowControl().getBusinessControl().getAsString(), sendEmail);
    RepositoryEntryPermissionChangeEvent changeEvent = new RepositoryEntryPermissionChangeEvent(editedIdentity);
    switch(type) {
        case owner:
            changeEvent.setRepoOwner(Boolean.TRUE);
            break;
        case tutor:
            changeEvent.setRepoTutor(Boolean.TRUE);
            break;
        case participant:
            changeEvent.setRepoParticipant(Boolean.TRUE);
            break;
    }
    List<RepositoryEntryPermissionChangeEvent> repoChanges = Collections.singletonList(changeEvent);
    for (RepositoryEntry repoEntry : res) {
        repositoryManager.updateRepositoryEntryMemberships(getIdentity(), ureq.getUserSession().getRoles(), repoEntry, repoChanges, reMailing);
    }
    // make sure all is committed before loading the model again (I see issues without)
    DBFactory.getInstance().commitAndCloseSession();
    MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), getLocale());
}
Also used : MailPackage(org.olat.core.util.mail.MailPackage) MailerResult(org.olat.core.util.mail.MailerResult) RepositoryEntryPermissionChangeEvent(org.olat.repository.model.RepositoryEntryPermissionChangeEvent) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 99 with MailerResult

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

the class UserImportController method sendMailToNewIdentities.

private void sendMailToNewIdentities(Map<TransientIdentity, Identity> newIdentities) {
    MailerResult result = new MailerResult();
    for (Map.Entry<TransientIdentity, Identity> newEntry : newIdentities.entrySet()) {
        if (newEntry.getKey() != null && newEntry.getValue() != null) {
            Identity newIdentity = newEntry.getValue();
            MailTemplate template = createMailTemplateForNewIdentity(newIdentity, newEntry.getKey());
            MailBundle bundle = mailService.makeMailBundle(null, newIdentity, template, getIdentity(), null, result);
            if (bundle != null) {
                mailService.sendExternMessage(bundle, result, true);
            }
        }
    }
}
Also used : 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) Map(java.util.Map) HashMap(java.util.HashMap)

Example 100 with MailerResult

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

the class MailManagerImpl method forwardToRealInbox.

@Override
public MailerResult forwardToRealInbox(Identity identity, DBMail mail, MailerResult result) {
    if (result == null) {
        result = new MailerResult();
    }
    List<DBMailAttachment> attachments = getAttachments(mail);
    Address to = createAddress(identity, result, true);
    MimeMessage message = createForwardMimeMessage(to, to, mail.getSubject(), mail.getBody(), attachments, result);
    if (message != null) {
        sendMessage(message, result);
    }
    return result;
}
Also used : DBMailAttachment(org.olat.core.util.mail.model.DBMailAttachment) InternetAddress(javax.mail.internet.InternetAddress) Address(javax.mail.Address) MailerResult(org.olat.core.util.mail.MailerResult) MimeMessage(javax.mail.internet.MimeMessage)

Aggregations

MailerResult (org.olat.core.util.mail.MailerResult)140 MailBundle (org.olat.core.util.mail.MailBundle)100 Identity (org.olat.core.id.Identity)82 MailContext (org.olat.core.util.mail.MailContext)66 MailContextImpl (org.olat.core.util.mail.MailContextImpl)66 MailTemplate (org.olat.core.util.mail.MailTemplate)46 Test (org.junit.Test)26 File (java.io.File)24 ArrayList (java.util.ArrayList)20 ContactList (org.olat.core.util.mail.ContactList)20 Locale (java.util.Locale)16 Translator (org.olat.core.gui.translator.Translator)16 VelocityContext (org.apache.velocity.VelocityContext)14 DBMailLight (org.olat.core.util.mail.model.DBMailLight)14 Date (java.util.Date)12 MailPackage (org.olat.core.util.mail.MailPackage)12 List (java.util.List)8 User (org.olat.core.id.User)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 Property (org.olat.properties.Property)7