use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class UserDeletionManager method sendUserDeleteEmailTo.
/**
* Send 'delete'- emails to a list of identities. The delete email is an announcement for the user-deletion.
*
* @param selectedIdentities
* @return String with warning message (e.g. email-address not valid, could not send email).
* If there is no warning, the return String is empty ("").
*/
public String sendUserDeleteEmailTo(List<Identity> selectedIdentities, MailTemplate template, boolean isTemplateChanged, String keyEmailSubject, String keyEmailBody, Identity sender, Translator pT) {
StringBuilder buf = new StringBuilder();
if (template != null) {
template.addToContext("responseTo", deletionModule.getEmailResponseTo());
for (Iterator<Identity> iter = selectedIdentities.iterator(); iter.hasNext(); ) {
Identity identity = iter.next();
if (!isTemplateChanged) {
// Email template has NOT changed => take translated version of subject and body text
Translator identityTranslator = Util.createPackageTranslator(SelectionController.class, I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage()));
template.setSubjectTemplate(identityTranslator.translate(keyEmailSubject));
template.setBodyTemplate(identityTranslator.translate(keyEmailBody));
}
template.putVariablesInMailContext(template.getContext(), identity);
logDebug(" Try to send Delete-email to identity=" + identity.getName() + " with email=" + identity.getUser().getProperty(UserConstants.EMAIL, null));
MailerResult result = new MailerResult();
MailBundle bundle = mailManager.makeMailBundle(null, identity, template, null, null, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
if (template.getCpfrom()) {
MailBundle ccBundle = mailManager.makeMailBundle(null, sender, template, sender, null, result);
if (ccBundle != null) {
mailManager.sendMessage(ccBundle);
}
}
if (result.getReturnCode() != MailerResult.OK) {
buf.append(pT.translate("email.error.send.failed", new String[] { identity.getUser().getProperty(UserConstants.EMAIL, null), identity.getName() })).append("\n");
}
logAudit("User-Deletion: Delete-email send to identity=" + identity.getName() + " with email=" + identity.getUser().getProperty(UserConstants.EMAIL, null));
markSendEmailEvent(identity);
}
} else {
// no template => User decides to sending no delete-email, mark only in lifecycle table 'sendEmail'
for (Iterator<Identity> iter = selectedIdentities.iterator(); iter.hasNext(); ) {
Identity identity = iter.next();
logAudit("User-Deletion: Move in 'Email sent' section without sending email, identity=" + identity.getName());
markSendEmailEvent(identity);
}
}
return buf.toString();
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
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.MailBundle in project OpenOLAT by OpenOLAT.
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.MailBundle in project OpenOLAT by OpenOLAT.
the class GTAAvailableTaskController method doSendConfirmationEmail.
private void doSendConfirmationEmail(Task assignedTask) {
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
ContactList contacts = new ContactList("participants");
if (GTAType.group.name().equals(gtaNode.getModuleConfiguration().getStringValue(GTACourseNode.GTASK_TYPE))) {
List<Identity> participants = businessGroupService.getMembers(assessedGroup, GroupRoles.participant.name());
contacts.addAllIdentites(participants);
bundle.setMetaId(UUID.randomUUID().toString());
} else {
contacts.add(assessedIdentity);
}
bundle.setContactList(contacts);
String[] args = new String[] { // 0 first name
getIdentity().getUser().getFirstName(), // 1 last name
getIdentity().getUser().getLastName(), // 2 course name
courseEnv.getCourseTitle(), // 3 task
assignedTask.getTaskName() };
String subject = translate("mail.confirm.assignment.subject", args);
String body = translate("mail.confirm.assignment.body", args);
bundle.setContent(subject, body);
mailManager.sendMessage(bundle);
}
use of org.olat.core.util.mail.MailBundle in project OpenOLAT by OpenOLAT.
the class ExportManager method sendEMail.
private void sendEMail(String email, Locale locale, String emailI18nSubkey) {
if (email == null || email.length() == 0) {
return;
}
if (locale == null) {
locale = I18nManager.getInstance().getCurrentThreadLocale();
}
Translator translator = Util.createPackageTranslator(ExportManager.class, locale);
try {
MailBundle bundle = new MailBundle();
bundle.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
bundle.setTo(email);
bundle.setContent(translator.translate(emailI18nSubkey + ".subject"), translator.translate(emailI18nSubkey + ".body"));
CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
} catch (Exception e) {
log_.error("Error sending information email to user that file was saved successfully.", e);
}
}
Aggregations