use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class EPShareListController method sendInvitation.
/**
* sends a link to the map to permitted users by email
*
* @param ureq
* @param wrapper
*/
private void sendInvitation(UserRequest ureq, EPSharePolicyWrapper wrapper) {
EPMapPolicy.Type shareType = wrapper.getType();
List<Identity> identitiesToMail = new ArrayList<Identity>();
Invitation invitation = null;
if (shareType.equals(EPMapPolicy.Type.allusers)) {
return;
} else if (shareType.equals(EPMapPolicy.Type.invitation)) {
invitation = wrapper.getInvitation();
} else if (shareType.equals(EPMapPolicy.Type.group)) {
List<BusinessGroup> groups = wrapper.getGroups();
List<Identity> members = businessGroupService.getMembers(groups, GroupRoles.coach.name(), GroupRoles.participant.name());
identitiesToMail.addAll(members);
} else if (shareType.equals(EPMapPolicy.Type.user)) {
identitiesToMail = wrapper.getIdentities();
}
wrapper.setInvitationSend(true);
ContactList contactList = null;
if (identitiesToMail.size() == 1) {
contactList = new ContactList(identitiesToMail.get(0).getUser().getProperty(UserConstants.EMAIL, ureq.getLocale()));
} else {
contactList = new ContactList(translate("map.share.invitation.mail.list"));
}
contactList.addAllIdentites(identitiesToMail);
String busLink = "";
if (invitation != null) {
contactList.add(invitation.getMail());
busLink = getInvitationLink(invitation, map);
} else {
BusinessControlFactory bCF = BusinessControlFactory.getInstance();
ContextEntry mapCE = bCF.createContextEntry(map.getOlatResource());
ArrayList<ContextEntry> cEList = new ArrayList<ContextEntry>();
cEList.add(mapCE);
busLink = bCF.getAsURIString(cEList, true);
}
boolean success = false;
try {
String first = getIdentity().getUser().getProperty(UserConstants.FIRSTNAME, null);
String last = getIdentity().getUser().getProperty(UserConstants.LASTNAME, null);
String sender = first + " " + last;
String[] bodyArgs = new String[] { busLink, sender };
MailContext context = new MailContextImpl(map.getOlatResource(), null, getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
bundle.setContactList(contactList);
bundle.setContent(translate("map.share.invitation.mail.subject"), translate("map.share.invitation.mail.body", bodyArgs));
MailerResult result = mailManager.sendMessage(bundle);
success = result.isSuccessful();
} catch (Exception e) {
logError("Error on sending invitation mail to contactlist, invalid address.", e);
}
if (success) {
showInfo("map.share.invitation.mail.success");
} else {
showError("map.share.invitation.mail.failure");
}
}
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 MembersMailController method doSendEmailToMember.
private void doSendEmailToMember(UserRequest ureq, ContactList contactList) {
boolean success = false;
try {
File[] attachmentArr = getAttachments();
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
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.MailContext in project openolat by klemens.
the class InfoMessageFrontendManagerImpl method sendInfoMessage.
@Override
public boolean sendInfoMessage(InfoMessage infoMessage, MailFormatter mailFormatter, Locale locale, Identity from, List<Identity> tos) {
infoMessageManager.saveInfoMessage(infoMessage);
boolean send = false;
if (tos != null && !tos.isEmpty()) {
Set<Long> identityKeySet = new HashSet<Long>();
ContactList contactList = new ContactList("Infos");
for (Identity to : tos) {
if (identityKeySet.contains(to.getKey()))
continue;
contactList.add(to);
identityKeySet.add(to.getKey());
}
try {
String subject = null;
String body = null;
if (mailFormatter != null) {
subject = mailFormatter.getSubject(infoMessage);
body = mailFormatter.getBody(infoMessage);
}
if (!StringHelper.containsNonWhitespace(subject)) {
subject = infoMessage.getTitle();
}
if (!StringHelper.containsNonWhitespace(body)) {
body = infoMessage.getMessage();
}
File attachment = null;
if (StringHelper.containsNonWhitespace(infoMessage.getAttachmentPath())) {
File root = getStoragePath().getBasefile();
attachment = new File(root, infoMessage.getAttachmentPath());
}
MailContext context = new MailContextImpl(mailFormatter.getBusinessPath());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFromId(from);
bundle.setContactList(contactList);
if (attachment != null) {
bundle.setContent(subject, body, attachment);
} else {
bundle.setContent(subject, body);
}
MailerResult result = mailManager.sendMessage(bundle);
send = result.isSuccessful();
} catch (Exception e) {
log.error("Cannot send info messages", e);
}
}
infoSubscriptionManager.markPublisherNews(infoMessage.getOLATResourceable(), infoMessage.getResSubPath());
MultiUserEvent mue = new MultiUserEvent("new_info_message");
coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(mue, oresFrontend);
return send;
}
use of org.olat.core.util.mail.MailContext in project openolat by klemens.
the class EnrollmentManager method addUserToWaitingList.
private boolean addUserToWaitingList(Identity identity, BusinessGroup group, ENCourseNode enNode, CoursePropertyManager coursePropertyManager, WindowControl wControl, Translator trans) {
// <- moved to bgs 1. Add user to group, fire events, do loggin etc.
// 2. Set first waiting-list date
String nowString = Long.toString(System.currentTimeMillis());
Property firstTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_WAITINGLIST_DATE);
if (firstTime == null) {
// create firsttime
firstTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_INITIAL_WAITINGLIST_DATE, null, null, nowString, null);
coursePropertyManager.saveProperty(firstTime);
}
// 3. Set waiting-list date property
Property thisTime = coursePropertyManager.findCourseNodeProperty(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_WAITINGLIST_DATE);
if (thisTime == null) {
// create firsttime
thisTime = coursePropertyManager.createCourseNodePropertyInstance(enNode, identity, null, ENCourseNode.PROPERTY_RECENT_WAITINGLIST_DATE, null, null, nowString, null);
coursePropertyManager.saveProperty(thisTime);
} else {
thisTime.setStringValue(nowString);
coursePropertyManager.updateProperty(thisTime);
}
// 4. Send notification mail
MailTemplate mailTemplate = BGMailHelper.createAddWaitinglistMailTemplate(group, 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());
return true;
}
Aggregations