use of org.olat.core.util.mail.MailerResult 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;
}
use of org.olat.core.util.mail.MailerResult 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");
}
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class MembersOverviewController method addMembers.
protected void addMembers(UserRequest ureq, StepsRunContext runContext) {
@SuppressWarnings("unchecked") List<Identity> members = (List<Identity>) runContext.get("members");
MemberPermissionChangeEvent changes = (MemberPermissionChangeEvent) runContext.get("permissions");
MailTemplate template = (MailTemplate) runContext.get("mailTemplate");
// commit changes to the repository entry
MailerResult result = new MailerResult();
MailPackage reMailing = new MailPackage(template, result, getWindowControl().getBusinessControl().getAsString(), template != null);
Roles roles = ureq.getUserSession().getRoles();
List<RepositoryEntryPermissionChangeEvent> repoChanges = changes.generateRepositoryChanges(members);
repositoryManager.updateRepositoryEntryMemberships(getIdentity(), roles, repoEntry, repoChanges, reMailing);
// commit all changes to the group memberships
List<BusinessGroupMembershipChange> allModifications = changes.generateBusinessGroupMembershipChange(members);
MailPackage mailing = new MailPackage(template, result, getWindowControl().getBusinessControl().getAsString(), template != null);
businessGroupService.updateMemberships(getIdentity(), allModifications, mailing);
MailHelper.printErrorsAndWarnings(result, getWindowControl(), roles.isOLATAdmin(), getLocale());
switchToAllMembers(ureq);
}
use of org.olat.core.util.mail.MailerResult in project OpenOLAT by OpenOLAT.
the class RepositoryMembersController method addMembers.
protected void addMembers(UserRequest ureq, StepsRunContext runContext) {
@SuppressWarnings("unchecked") List<Identity> members = (List<Identity>) runContext.get("members");
MailTemplate template = (MailTemplate) runContext.get("mailTemplate");
MemberPermissionChangeEvent changes = (MemberPermissionChangeEvent) runContext.get("permissions");
// commit changes to the repository entry
MailerResult result = new MailerResult();
MailPackage reMailing = new MailPackage(template, result, getWindowControl().getBusinessControl().getAsString(), template != null);
List<RepositoryEntryPermissionChangeEvent> repoChanges = changes.generateRepositoryChanges(members);
repositoryManager.updateRepositoryEntryMemberships(getIdentity(), ureq.getUserSession().getRoles(), repoEntry, repoChanges, reMailing);
// commit all changes to the group memberships
List<BusinessGroupMembershipChange> allModifications = changes.generateBusinessGroupMembershipChange(members);
MailPackage bgMailing = new MailPackage(template, result, getWindowControl().getBusinessControl().getAsString(), template != null);
businessGroupService.updateMemberships(getIdentity(), allModifications, bgMailing);
MailHelper.printErrorsAndWarnings(result, getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), getLocale());
}
use of org.olat.core.util.mail.MailerResult 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);
}
}
}
Aggregations