use of org.olat.core.util.mail.MailContext in project openolat by klemens.
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());
}
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
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.MailContext in project openolat by klemens.
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;
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
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;
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
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");
}
}
Aggregations