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());
}
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");
}
}
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());
}
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);
}
}
}
}
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;
}
Aggregations