use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class MembersAvatarDisplayRunController method doSendEmailToMember.
private void doSendEmailToMember(Member member, UserRequest ureq) {
if (!editable)
return;
ContactList memberList;
if (courseEnv == null) {
memberList = new ContactList(translate("members.to", new String[] { member.getFullName(), businessGroup.getName() }));
} else {
memberList = new ContactList(translate("members.to", new String[] { member.getFullName(), courseEnv.getCourseTitle() }));
}
Identity identity = securityManager.loadIdentityByKey(member.getKey());
memberList.add(identity);
doSendEmailToMember(memberList, ureq);
}
use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class MembersMailController method doSend.
private void doSend(UserRequest ureq) {
ContactList contactList = new ContactList("");
if (courseEnv == null) {
if (coachEl != null && coachEl.isAtLeastSelected(1)) {
List<Long> identityKeys = new ArrayList<>(coachList.size());
for (Member coach : coachList) {
identityKeys.add(coach.getKey());
}
List<Identity> coaches = securityManager.loadIdentityByKeys(identityKeys);
contactList.addAllIdentites(coaches);
}
if (participantEl != null && participantEl.isAtLeastSelected(1)) {
List<Long> identityKeys = new ArrayList<>(participantList.size());
for (Member participant : participantList) {
identityKeys.add(participant.getKey());
}
List<Identity> participants = securityManager.loadIdentityByKeys(identityKeys);
contactList.addAllIdentites(participants);
}
if (waitingEl != null && waitingEl.isAtLeastSelected(1)) {
List<Long> identityKeys = new ArrayList<>(waitingList.size());
for (Member waiter : waitingList) {
identityKeys.add(waiter.getKey());
}
List<Identity> waiters = securityManager.loadIdentityByKeys(identityKeys);
contactList.addAllIdentites(waiters);
}
} else {
if (ownerEl != null && ownerEl.isAtLeastSelected(1)) {
RepositoryEntry courseRepositoryEntry = courseEnv.getCourseGroupManager().getCourseEntry();
List<Identity> owners = repositoryService.getMembers(courseRepositoryEntry, GroupRoles.owner.name());
contactList.addAllIdentites(owners);
}
if (coachEl != null && coachEl.isAtLeastSelected(1)) {
Set<Long> sendToWhatYouSee = new HashSet<>();
for (Member coach : coachList) {
sendToWhatYouSee.add(coach.getKey());
}
CourseGroupManager cgm = courseEnv.getCourseGroupManager();
avoidInvisibleMember(cgm.getCoachesFromBusinessGroups(), contactList, sendToWhatYouSee);
avoidInvisibleMember(cgm.getCoaches(), contactList, sendToWhatYouSee);
}
if (participantEl != null && participantEl.isAtLeastSelected(1)) {
Set<Long> sendToWhatYouSee = new HashSet<>();
for (Member participant : participantList) {
sendToWhatYouSee.add(participant.getKey());
}
CourseGroupManager cgm = courseEnv.getCourseGroupManager();
avoidInvisibleMember(cgm.getParticipantsFromBusinessGroups(), contactList, sendToWhatYouSee);
avoidInvisibleMember(cgm.getParticipants(), contactList, sendToWhatYouSee);
}
}
if (individualEl != null && individualEl.isAtLeastSelected(1) && selectedMembers != null && selectedMembers.size() > 0) {
List<Long> identityKeys = new ArrayList<>(selectedMembers.size());
for (Member member : selectedMembers) {
identityKeys.add(member.getKey());
}
List<Identity> selectedIdentities = securityManager.loadIdentityByKeys(identityKeys);
contactList.addAllIdentites(selectedIdentities);
}
if (externalEl != null && externalEl.isAtLeastSelected(1)) {
String value = externalAddressesEl.getValue();
if (StringHelper.containsNonWhitespace(value)) {
for (StringTokenizer tokenizer = new StringTokenizer(value, ",\r\n", false); tokenizer.hasMoreTokens(); ) {
String email = tokenizer.nextToken().trim();
contactList.add(new EMailIdentity(email, getLocale()));
}
}
}
doSendEmailToMember(ureq, contactList);
}
use of org.olat.core.util.mail.ContactList 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.ContactList in project openolat by klemens.
the class DENManager method sendParticipantsMessage.
/**
* Generates the mail window
* @param ureq
* @param wControl
* @param listener
* @param velocity_root
* @param trans
* @param participants
* @return VelocityContainer
*/
protected VelocityContainer sendParticipantsMessage(UserRequest ureq, WindowControl wControl, DefaultController listener, String velocity_root, Translator trans, List<Identity> participants) {
VelocityContainer sendMessageVC = new VelocityContainer("sendmessage", velocity_root + "/sendmessage.html", trans, listener);
ContactMessage cmsg = new ContactMessage(ureq.getIdentity());
ContactList contactList = null;
if (participants.size() == 1) {
contactList = new ContactList(participants.get(0).getUser().getProperty(UserConstants.EMAIL, ureq.getLocale()));
} else {
contactList = new ContactList(trans.translate("participants.message.to"));
}
contactList.addAllIdentites(participants);
cmsg.addEmailTo(contactList);
ContactFormController contactCtr = new ContactFormController(ureq, wControl, false, false, false, cmsg);
contactCtr.addControllerListener(listener);
sendMessageVC.contextPut("title", trans.translate("participants.message"));
sendMessageVC.put("contactForm", contactCtr.getInitialComponent());
return sendMessageVC;
}
use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class LoginTableDataModel method sendMail.
/**
* Send the mail with informations: who deletes, when, list of deleted users
* list of not deleted users, reason for deletion
*/
public void sendMail() {
String recipient = WebappHelper.getMailConfig("mailDeleteUser");
if (recipient.equals("disabled")) {
return;
}
StringBuilder loginsFound = new StringBuilder();
for (String login : lstLoginsFound) {
loginsFound.append(login + "\n");
}
StringBuilder loginsNotfound = new StringBuilder();
for (String login : lstLoginsNotfound) {
loginsNotfound.append(login + "\n");
}
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, getLocale());
String[] bodyArgs = new String[] { getIdentity().getName(), loginsFound.toString(), loginsNotfound.toString(), reason, df.format(new Date()) };
ContactList cl = new ContactList(recipient);
cl.add(recipient);
cl.add(getIdentity());
try {
MailBundle bundle = new MailBundle();
bundle.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
bundle.setContent(translate("mail.subject"), translate("mail.body", bodyArgs));
bundle.setContactList(cl);
mailService.sendMessage(bundle);
} catch (Exception e) {
logError("Notificatoin mail for bulk deletion could not be sent", null);
}
}
Aggregations