use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class DENManageParticipantsController method createParticipantsMail.
private void createParticipantsMail(UserRequest ureq, List<Identity> participants) {
VelocityContainer sendMessageVC = createVelocityContainer("sendmessage");
ContactMessage cmsg = new ContactMessage(ureq.getIdentity());
ContactList contactList = new ContactList(translate("participants.message.to"));
contactList.addAllIdentites(participants);
cmsg.addEmailTo(contactList);
removeAsListenerAndDispose(contactCtr);
contactCtr = new ContactFormController(ureq, getWindowControl(), false, false, false, cmsg);
listenTo(contactCtr);
sendMessageVC.contextPut("title", translate("participants.message"));
sendMessageVC.put("contactForm", contactCtr.getInitialComponent());
removeAsListenerAndDispose(notificationCmc);
notificationCmc = new CloseableModalController(getWindowControl(), "close", sendMessageVC);
listenTo(notificationCmc);
notificationCmc.activate();
}
use of org.olat.core.util.mail.ContactList in project openolat by klemens.
the class MembersTableController method doSendEmailToMember.
private void doSendEmailToMember(MemberView member, UserRequest ureq) {
if (!editable)
return;
ContactList memberList;
Identity identity = securityManager.loadIdentityByKey(member.getIdentityKey());
String fullName = userManager.getUserDisplayName(identity);
if (courseEnv == null) {
memberList = new ContactList(translate("members.to", new String[] { fullName, businessGroup.getName() }));
} else {
memberList = new ContactList(translate("members.to", new String[] { fullName, courseEnv.getCourseTitle() }));
}
memberList.add(identity);
doSendEmailToMember(memberList, ureq);
}
use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.
the class MailManagerImpl method appendRecipients.
private void appendRecipients(DBMailImpl mail, List<ContactList> ccLists, List<Address> toAddress, List<Address> ccAddress, boolean visible, boolean makeRealMail, MailerResult result) throws AddressException {
// append cc/bcc recipients
if (ccLists != null && !ccLists.isEmpty()) {
for (ContactList contactList : ccLists) {
if (makeRealMail && StringHelper.containsNonWhitespace(contactList.getName())) {
Address[] groupAddress = InternetAddress.parse(contactList.getRFC2822Name() + ";");
if (groupAddress != null && groupAddress.length > 0) {
for (Address groupAdd : groupAddress) {
toAddress.add(groupAdd);
}
}
}
for (String email : contactList.getStringEmails().values()) {
DBMailRecipient recipient = new DBMailRecipient();
recipient.setEmailAddress(email);
recipient.setGroup(contactList.getName());
recipient.setVisible(visible);
recipient.setDeleted(Boolean.FALSE);
recipient.setMarked(Boolean.FALSE);
recipient.setRead(Boolean.FALSE);
mail.getRecipients().add(recipient);
if (makeRealMail) {
createAddress(ccAddress, recipient, false, result, false);
}
}
for (Identity identityEmail : contactList.getIdentiEmails().values()) {
DBMailRecipient recipient = new DBMailRecipient();
if (identityEmail instanceof IdentityImpl) {
recipient.setRecipient(identityEmail);
} else {
recipient.setEmailAddress(identityEmail.getUser().getProperty(UserConstants.EMAIL, null));
}
recipient.setGroup(contactList.getName());
recipient.setVisible(visible);
recipient.setDeleted(Boolean.FALSE);
recipient.setMarked(Boolean.FALSE);
recipient.setRead(Boolean.FALSE);
mail.getRecipients().add(recipient);
if (makeRealMail) {
createAddress(ccAddress, recipient, false, result, false);
}
}
}
}
}
use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.
the class MailManagerImpl method createMimeMessage.
private MimeMessage createMimeMessage(Identity fromId, String mailFrom, Identity toId, String to, Identity ccId, List<ContactList> bccLists, MailContent content, MailerResult result) {
try {
Address from;
if (StringHelper.containsNonWhitespace(mailFrom)) {
from = createFromAddress(mailFrom, result);
} else if (fromId != null) {
from = createFromAddress(fromId, result);
} else {
// fxdiff: change from/replyto, see FXOLAT-74 . if no from is set, use default sysadmin-address (adminemail).
from = createAddress(WebappHelper.getMailConfig("mailReplyTo"));
if (from == null) {
log.error("MailConfigError: mailReplyTo is not set", null);
}
}
List<Address> toList = new ArrayList<Address>();
if (StringHelper.containsNonWhitespace(to)) {
Address[] toAddresses = InternetAddress.parse(to);
for (Address toAddress : toAddresses) {
toList.add(toAddress);
}
} else if (toId != null) {
Address toAddress = createAddress(toId, result, true);
if (toAddress != null) {
toList.add(toAddress);
}
}
List<Address> ccList = new ArrayList<Address>();
if (ccId != null) {
Address ccAddress = createAddress(ccId, result, true);
if (ccAddress != null) {
ccList.add(ccAddress);
}
}
// add bcc contact lists
List<Address> bccList = new ArrayList<Address>();
if (bccLists != null) {
for (ContactList contactList : bccLists) {
if (StringHelper.containsNonWhitespace(contactList.getName())) {
Address[] groupNames = InternetAddress.parse(contactList.getRFC2822Name() + ";");
for (Address groupName : groupNames) {
toList.add(groupName);
}
}
Address[] members = contactList.getEmailsAsAddresses();
for (Address member : members) {
bccList.add(member);
}
}
}
Address[] tos = toList.toArray(new Address[toList.size()]);
Address[] ccs = ccList.toArray(new Address[ccList.size()]);
Address[] bccs = bccList.toArray(new Address[bccList.size()]);
return createMimeMessage(from, tos, ccs, bccs, content.getSubject(), content.getBody(), content.getAttachments(), result);
} catch (MessagingException e) {
log.error("", e);
return null;
}
}
use of org.olat.core.util.mail.ContactList in project OpenOLAT by OpenOLAT.
the class BulkAssessmentTask method sendFeedback.
private void sendFeedback(List<BulkAssessmentFeedback> feedbacks) {
if (task == null) {
log.error("Haven't a task to know creator and modifiers of the task", null);
return;
}
Identity creator = task.getCreator();
String language = creator.getUser().getPreferences().getLanguage();
Locale locale = I18nManager.getInstance().getLocaleOrDefault(language);
Translator translator = Util.createPackageTranslator(BulkAssessmentOverviewController.class, locale, Util.createPackageTranslator(AssessmentManager.class, locale));
MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
TaskExecutorManager taskManager = CoreSpringFactory.getImpl(TaskExecutorManager.class);
String feedbackStr = renderFeedback(feedbacks, translator);
MailBundle mail = new MailBundle();
mail.setToId(creator);
mail.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
List<Identity> modifiers = taskManager.getModifiers(task);
if (modifiers.size() > 0) {
ContactList cc = new ContactList("CC");
cc.addAllIdentites(modifiers);
mail.setContactList(cc);
}
String businessPath = "";
ICourse course = CourseFactory.loadCourse(courseRes);
CourseNode node = course.getRunStructure().getNode(courseNodeIdent);
String courseTitle = course.getCourseTitle();
String nodeTitle = node.getShortTitle();
String numOfAssessedIds = Integer.toString(datas == null ? 0 : datas.getRowsSize());
String date = Formatter.getInstance(locale).formatDateAndTime(new Date());
mail.setContext(new MailContextImpl(courseRes, courseNodeIdent, businessPath));
String subject = translator.translate("confirmation.mail.subject", new String[] { courseTitle, nodeTitle });
String body = translator.translate("confirmation.mail.body", new String[] { courseTitle, nodeTitle, feedbackStr, numOfAssessedIds, date });
mail.setContent(subject, body);
mailManager.sendMessage(mail);
}
Aggregations