use of org.olat.core.util.mail.MailManager 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);
}
use of org.olat.core.util.mail.MailManager in project OpenOLAT by OpenOLAT.
the class RepositoryMailing method sendEmail.
public static void sendEmail(Identity ureqIdentity, Identity identity, RepositoryEntry re, Type type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
String email = identity.getUser().getProperty(UserConstants.EMAIL, null);
String emailAlt = identity.getUser().getProperty(UserConstants.INSTITUTIONALEMAIL, null);
if (!StringHelper.containsNonWhitespace(email) && !StringHelper.containsNonWhitespace(emailAlt)) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
RepositoryModule repositoryModule = CoreSpringFactory.getImpl(RepositoryModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!repositoryModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
template = getDefaultTemplate(type, re, ureqIdentity);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[RepositoryEntry:" + re.getKey() + "]");
}
String metaId = mailing == null ? null : mailing.getUuid();
MailerResult result = new MailerResult();
MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailManager.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailManager.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
use of org.olat.core.util.mail.MailManager in project OpenOLAT by OpenOLAT.
the class BusinessGroupMailing method sendEmail.
protected static void sendEmail(Identity ureqIdentity, Identity identity, BusinessGroupShort group, MailType type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
BusinessGroupModule groupModule = CoreSpringFactory.getImpl(BusinessGroupModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!groupModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
// booking by myself
if (type != null && type == MailType.addParticipant && ureqIdentity != null && ureqIdentity.equals(identity)) {
template = BGMailHelper.createAddMyselfMailTemplate(group, ureqIdentity);
} else {
template = getDefaultTemplate(type, group, ureqIdentity);
}
} else if (group != null && template.getContext() != null && needTemplateEnhancement(template)) {
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
template = new MailTemplateDelegate(template, group, repoEntries);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[BusinessGroup:" + group.getKey() + "]");
}
MailerResult result = new MailerResult();
String metaId = mailing != null ? mailing.getUuid() : null;
MailManager mailService = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailService.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailService.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
use of org.olat.core.util.mail.MailManager in project OpenOLAT by OpenOLAT.
the class RegistrationWebService method register.
/**
* Register with the specified email
* @response.representation.200.doc Registration successful
* @response.representation.304.doc Already registered, HTTP-Header location set to redirect
* @response.representation.400.doc Email address not allowed
* @param email The email address
* @param request The HTTP Request
* @return
*/
@PUT
public Response register(@QueryParam("email") String email, @Context HttpServletRequest request) {
if (!CoreSpringFactory.getImpl(RegistrationModule.class).isSelfRegistrationEnabled()) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ResponseBuilder response;
Locale locale = getLocale(request);
Translator translator = getTranslator(locale);
MailManager mailM = CoreSpringFactory.getImpl(MailManager.class);
UserManager userManager = UserManager.getInstance();
RegistrationManager rm = CoreSpringFactory.getImpl(RegistrationManager.class);
boolean foundUser = userManager.findUniqueIdentityByEmail(email) != null;
boolean noNewUserWithEmail = !userManager.isEmailAllowed(email);
String serverpath = Settings.getServerContextPathURI();
if (foundUser && noNewUserWithEmail) {
// redirect
URI redirectUri = UriBuilder.fromUri(Settings.getServerContextPathURI()).build();
response = Response.ok().status(Status.NOT_MODIFIED).location(redirectUri);
} else if (userManager.isEmailAllowed(email)) {
String ip = request.getRemoteAddr();
TemporaryKey tk = null;
UserModule userModule = CoreSpringFactory.getImpl(UserModule.class);
if (userModule.isEmailUnique()) {
tk = rm.loadTemporaryKeyByEmail(email);
}
if (tk == null) {
tk = rm.loadOrCreateTemporaryKeyByEmail(email, ip, RegistrationManager.REGISTRATION);
}
String today = DateFormat.getDateInstance(DateFormat.LONG, locale).format(new Date());
String[] bodyAttrs = new String[] { serverpath, tk.getRegistrationKey(), CoreSpringFactory.getImpl(I18nModule.class).getLocaleKey(locale) };
String[] whereFromAttrs = new String[] { serverpath, today, ip };
String body = translator.translate("reg.body", bodyAttrs) + SEPARATOR + translator.translate("reg.wherefrom", whereFromAttrs);
try {
MailBundle bundle = new MailBundle();
bundle.setTo(email);
bundle.setContent(translator.translate("reg.subject"), body);
MailerResult result = mailM.sendExternMessage(bundle, null, true);
if (result.isSuccessful()) {
response = Response.ok();
} else {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
log.error("", e);
}
} else {
response = Response.serverError().status(Status.BAD_REQUEST);
}
return response.build();
}
use of org.olat.core.util.mail.MailManager in project openolat by klemens.
the class RegistrationWebService method register.
/**
* Register with the specified email
* @response.representation.200.doc Registration successful
* @response.representation.304.doc Already registered, HTTP-Header location set to redirect
* @response.representation.400.doc Email address not allowed
* @param email The email address
* @param request The HTTP Request
* @return
*/
@PUT
public Response register(@QueryParam("email") String email, @Context HttpServletRequest request) {
if (!CoreSpringFactory.getImpl(RegistrationModule.class).isSelfRegistrationEnabled()) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ResponseBuilder response;
Locale locale = getLocale(request);
Translator translator = getTranslator(locale);
MailManager mailM = CoreSpringFactory.getImpl(MailManager.class);
UserManager userManager = UserManager.getInstance();
RegistrationManager rm = CoreSpringFactory.getImpl(RegistrationManager.class);
boolean foundUser = userManager.findUniqueIdentityByEmail(email) != null;
boolean noNewUserWithEmail = !userManager.isEmailAllowed(email);
String serverpath = Settings.getServerContextPathURI();
if (foundUser && noNewUserWithEmail) {
// redirect
URI redirectUri = UriBuilder.fromUri(Settings.getServerContextPathURI()).build();
response = Response.ok().status(Status.NOT_MODIFIED).location(redirectUri);
} else if (userManager.isEmailAllowed(email)) {
String ip = request.getRemoteAddr();
TemporaryKey tk = null;
UserModule userModule = CoreSpringFactory.getImpl(UserModule.class);
if (userModule.isEmailUnique()) {
tk = rm.loadTemporaryKeyByEmail(email);
}
if (tk == null) {
tk = rm.loadOrCreateTemporaryKeyByEmail(email, ip, RegistrationManager.REGISTRATION);
}
String today = DateFormat.getDateInstance(DateFormat.LONG, locale).format(new Date());
String[] bodyAttrs = new String[] { serverpath, tk.getRegistrationKey(), CoreSpringFactory.getImpl(I18nModule.class).getLocaleKey(locale) };
String[] whereFromAttrs = new String[] { serverpath, today, ip };
String body = translator.translate("reg.body", bodyAttrs) + SEPARATOR + translator.translate("reg.wherefrom", whereFromAttrs);
try {
MailBundle bundle = new MailBundle();
bundle.setTo(email);
bundle.setContent(translator.translate("reg.subject"), body);
MailerResult result = mailM.sendExternMessage(bundle, null, true);
if (result.isSuccessful()) {
response = Response.ok();
} else {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
log.error("", e);
}
} else {
response = Response.serverError().status(Status.BAD_REQUEST);
}
return response.build();
}
Aggregations