use of org.olat.core.util.mail.MailContextImpl 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;
}
use of org.olat.core.util.mail.MailContextImpl 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.MailContextImpl 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.MailContextImpl 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);
}
}
}
use of org.olat.core.util.mail.MailContextImpl in project OpenOLAT by OpenOLAT.
the class EnrollmentManager method doCancelEnrollmentInWaitingList.
public void doCancelEnrollmentInWaitingList(final Identity identity, final BusinessGroup enrolledWaitingListGroup, final ENCourseNode enNode, final CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
// 1. Remove group membership, fire events, do loggin etc.
businessGroupService.removeFromWaitingList(identity, Collections.singletonList(identity), enrolledWaitingListGroup, null);
// 2. Remove enrollmentdate property
// only remove last time date, not firsttime
Property lastTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_WAITINGLIST_DATE);
if (lastTime != null) {
coursePropertyManager.deleteProperty(lastTime);
}
// 3. Send notification mail
MailTemplate mailTemplate = BGMailHelper.createRemoveWaitinglistMailTemplate(enrolledWaitingListGroup, identity);
// fxdiff VCRP-16: intern mail system
MailContext context = new MailContextImpl(wControl.getBusinessControl().getAsString());
MailerResult result = new MailerResult();
MailBundle bundle = mailManager.makeMailBundle(context, identity, mailTemplate, null, null, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
MailHelper.printErrorsAndWarnings(result, wControl, false, trans.getLocale());
}
Aggregations