public User lookupUserFromEmail(String email) throws AdministrationEmailException { Collection<User> users; try { users = userManager.lookupUsers("user.business-info.online.email", email); } catch (SecurityException e) { throw new AdministrationEmailException(e); } if (users.isEmpty()) { throw new AdministrationEmailException(USER_NOT_FOUND_FROM_EMAIL + email); } return users.iterator().next(); // return the first one and hopefully the only (FIXME: need unique constraints) }
public String mergeEmailTemplate(PortletConfig portletConfig, Map<String, String> attributes, String attributesName, String template) throws AdministrationEmailException { VelocityContext context = new VelocityContext(); context.put(attributesName, attributes); StringWriter writer = new StringWriter(); try { String realTemplatePath = portletConfig.getPortletContext().getRealPath(template); FileReader templateReader = new FileReader(realTemplatePath); velocityEngine.evaluate(context, writer, "UserEmailProcessor", templateReader); } catch (Exception e) { throw new AdministrationEmailException( "Failed to generate email text for email template " + template, e); } String buffer = writer.getBuffer().toString(); return buffer; }
String message = "Failed to send forgotten password email to user with email address because " + ex.getMessage(); log.error(message, ex); throw new AdministrationEmailException(message, ex