List of usage examples for org.springframework.mail SimpleMailMessage SimpleMailMessage
public SimpleMailMessage(SimpleMailMessage original)
From source file:com.gnizr.web.action.user.RegisterUser.java
private boolean sendEmailVerification(String token, User user) { Map<String, Object> model = new HashMap<String, Object>(); model.put("token", token); model.put("username", user.getUsername()); model.put("gnizrConfiguration", getGnizrConfiguration()); if (getVerifyEmailTemplate() == null) { logger.error("RegisterUser: templateMessge bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; }//from w ww. j a va 2 s . co m String toEmail = user.getEmail(); if (toEmail == null) { logger.error("RegisterUser: the email of user " + user.getUsername() + " is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_EMAIL_UNDEF)); return false; } SimpleMailMessage msg = new SimpleMailMessage(getVerifyEmailTemplate()); msg.setTo(toEmail); if (msg.getFrom() == null) { String contactEmail = getGnizrConfiguration().getSiteContactEmail(); if (contactEmail != null) { msg.setFrom(contactEmail); } else { msg.setFrom("help@localhost"); } } Template fmTemplate = null; String text = null; try { fmTemplate = freemarkerEngine.getTemplate("login/verifyemail-template.ftl"); text = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate, model); } catch (Exception e) { logger.error("RegisterUser: error creating message template from Freemarker engine"); } msg.setText(text); if (getMailSender() == null) { logger.error("RegisterUser: mailSender bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; } try { getMailSender().send(msg); return true; } catch (Exception e) { logger.error("RegisterUser: send mail error. " + e); addActionError(String.valueOf(ActionErrorCode.ERROR_INTERNAL)); } return false; }
From source file:fi.koku.pyh.controller.EditFamilyInformationController.java
/** * Action method for adding new family members. * //w ww . j a v a 2 s. co m * @param request - portlet action request * @param response - portlet action response * @throws FamilyNotFoundException * @throws TooManyFamiliesException * @throws fi.koku.services.entity.customer.v1.ServiceFault * @throws fi.koku.services.entity.community.v1.ServiceFault */ @ActionMapping(params = "action=addUsersToFamily") public void addUsersToFamily(ActionRequest request, ActionResponse response) throws FamilyNotFoundException, TooManyFamiliesException, fi.koku.services.entity.customer.v1.ServiceFault, fi.koku.services.entity.community.v1.ServiceFault { String userPic = UserInfoUtils.getPicFromSession(request); HashMap<String, String> personMap = new HashMap<String, String>(); String familyCommunityId = request.getParameter("familyCommunityId"); String personPicFromJsp = request.getParameter("userPic"); String personRoleFromJsp = request.getParameter("userRole"); personMap.put(personPicFromJsp, personRoleFromJsp); boolean childsGuardianshipInformationNotFound = false; try { if (logger.isDebugEnabled()) { logger.debug("addUsersToFamily(): adding persons:"); Set<String> set = personMap.keySet(); Iterator<String> it = set.iterator(); while (it.hasNext()) { String personPic = it.next(); logger.debug("person pic: " + personPic); } } if (familyCommunityId == null) { throw new FamilyNotFoundException( "EditFamilyInformationController.addUsersToFamily: cannot add family members because family community does not exist!"); } Set<String> keys = personMap.keySet(); Iterator<String> si = keys.iterator(); while (si.hasNext()) { String memberToAddPic = si.next(); String role = personMap.get(memberToAddPic); CommunityRole communityRole = CommunityRole.create(role); List<String> recipients = generateRecipients(memberToAddPic, communityRole, userPic/*current user's pic*/); if (CommunityRole.PARENT.equals(communityRole) || CommunityRole.FATHER.equals(communityRole) || CommunityRole.MOTHER.equals(communityRole)) { Log.getInstance().send(userPic, "", "pyh.membership.request", "Sending membership request to add person " + memberToAddPic + " into family"); messageHelper.sendParentAdditionMessage(familyCommunityId, memberToAddPic, userPic, communityRole); } else if (CommunityRole.CHILD.equals(communityRole) && recipients.size() == 0) { // we don't have guardian information for the child so we can't send the request Log.getInstance().send(userPic, "", "pyh.membership.request", "Cannot send approval request because guardian for child " + memberToAddPic + " is not found"); String messageSubject = messageSource.getMessage("ui.pyh.mail.missing.information.subject", null, "", Locale.getDefault()); String messageText = messageSource.getMessage("ui.pyh.mail.missing.information.text", new Object[] { memberToAddPic }, "", Locale.getDefault()); // send mail notification to KoKu support SimpleMailMessage mailMessage = new SimpleMailMessage(this.templateMessage); mailMessage.setFrom(PyhConstants.KOKU_FROM_EMAIL_ADDRESS); mailMessage.setTo(PyhConstants.KOKU_SUPPORT_EMAIL_ADDRESS); mailMessage.setSubject(messageSubject); mailMessage.setText(messageText); try { this.mailSender.send(mailMessage); } catch (MailException me) { // if mail sending fails, PYH operation continues normally logger.error( "EditFamilyInformationController.addUsersToFamily: sending mail to KoKu support failed!", me); } // notify end user that family membership request cannot be sent throw new GuardianForChildNotFoundException( "Guardian for child (pic: " + memberToAddPic + ") not found!"); } else if (recipients.size() == 0) { insertInto(userPic, memberToAddPic, communityRole); } else { Log.getInstance().send(userPic, "", "pyh.membership.request", "Sending membership request to add person " + memberToAddPic + " into family"); messageHelper.sendFamilyAdditionMessage(familyCommunityId, recipients, userPic, memberToAddPic, communityRole); } } } catch (GuardianForChildNotFoundException gnfe) { logger.error( "EditFamilyInformationController.addUsersToFamily() caught GuardianForChildNotFoundException: cannot send membership " + "request because guardian for the child was not found. The child was not added into the family."); // show error message in JSP view childsGuardianshipInformationNotFound = true; } response.setRenderParameter("childsGuardianshipInformationNotFound", String.valueOf(childsGuardianshipInformationNotFound)); response.setRenderParameter("action", "editFamilyInformation"); }
From source file:edu.washington.iam.registry.ws.RelyingPartyController.java
@RequestMapping(value = "/rp", method = RequestMethod.PUT) public ModelAndView putRelyingParty(@RequestParam(value = "id", required = true) String id, @RequestParam(value = "mdid", required = true) String mdid, @RequestParam(value = "role", required = false) String role, @RequestParam(value = "xsrf", required = false) String paramXsrf, InputStream in, HttpServletRequest request, HttpServletResponse response) { RPSession session = processRequestInfo(request, response, false); if (session == null) return (emptyMV()); log.info("PUT update for: " + id); int status = 200; if (session.isBrowser && !(paramXsrf != null && paramXsrf.equals(session.xsrfCode))) { log.info("got invalid xsrf=" + paramXsrf + ", expected+" + session.xsrfCode); return emptyMV("invalid session (xsrf)"); }//from w w w. j ava 2 s. c o m ModelAndView mv = emptyMV("OK dokey"); try { if (!userCanEdit(session, id)) { status = 401; mv.addObject("alert", "You are not an owner of that entity."); response.setStatus(status); return mv; } } catch (DNSVerifyException e) { mv.addObject("alert", "Could not verify ownership:\n" + e.getCause()); response.setStatus(500); return mv; } RelyingParty relyingParty = null; try { Document doc = null; DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); doc = builder.parse(in); relyingParty = new RelyingParty(doc.getDocumentElement(), mdid, rpManager.isMetadataEditable(mdid)); } catch (Exception e) { log.info("parse error: " + e); status = 400; mv.addObject("alert", "The posted document was not valid:\n" + e); response.setStatus(status); return mv; } try { status = rpManager.updateRelyingParty(relyingParty, mdid); } catch (RelyingPartyException e) { status = 400; mv.addObject("alert", "Update failed:\n" + e.getMessage()); response.setStatus(status); return mv; } SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(mailTo); String act = "updated"; if (status == 201) act = "created"; else if (status >= 400) act = "attempted edit of"; msg.setSubject("Service provider metadata " + act + " by " + session.remoteUser); msg.setText("User '" + session.remoteUser + "' " + act + " metadata for '" + id + "'.\nRequest status: " + status + "\n\nThis message is advisory. No response is indicated."); try { this.mailSender.send(msg); } catch (MailException ex) { log.error("sending mail: " + ex.getMessage()); } response.setStatus(status); return mv; }
From source file:edu.washington.iam.registry.ws.RelyingPartyController.java
@RequestMapping(value = "/ws/metadata", method = RequestMethod.PUT) public ModelAndView putRelyingParty(@RequestParam(value = "id", required = true) String id, @RequestParam(value = "mdid", required = true) String mdid, InputStream in, HttpServletRequest request, HttpServletResponse response) {/*from w w w . j av a 2 s.c om*/ RPSession session = processRequestInfo(request, response, false); if (session == null) return (emptyMV()); log.info("API PUT update for: " + id); int status = 403; ModelAndView mv = basicModelAndView(session, "xml", "empty"); String dns = dnsFromEntityId(id); for (int i = 0; i < session.altNames.size(); i++) { if (dns.equals(session.altNames.get(i))) { log.info("dns match found for " + dns); status = 200; } } if (status == 403) { mv.addObject("alert", "You are not an owner of that entity."); response.setStatus(status); return mv; } if (!rpManager.isMetadataEditable(mdid)) { status = 400; mv.addObject("alert", "The metadata was not found or is not editable"); response.setStatus(status); return mv; } RelyingParty rp = null; try { Document doc = null; DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); doc = builder.parse(in); rp = new RelyingParty(doc.getDocumentElement(), mdid, rpManager.isMetadataEditable(mdid)); } catch (Exception e) { log.info("parse error: " + e); status = 400; mv.addObject("alert", "The posted document was not valid:\n" + e); response.setStatus(status); return mv; } if (rp.getEntityId().equals(id)) { try { rpManager.updateRelyingParty(rp, mdid); } catch (RelyingPartyException e) { status = 400; mv.addObject("alert", "Update of the metadata failed:\n" + e); } } else { mv.addObject("alert", String.format("Id %s doesn't match %s", rp.getEntityId(), id)); } SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(mailTo); String act = "updated"; if (status == 201) act = "created"; else if (status >= 400) act = "attempted edit of"; msg.setSubject("Service provider metadata " + act + " by " + session.remoteUser); msg.setText("User '" + session.remoteUser + "' " + act + " metadata for '" + id + "'.\nRequest status: " + status + "\n\nThis message is advisory. No response is indicated."); try { this.mailSender.send(msg); } catch (MailException ex) { log.error("sending mail: " + ex.getMessage()); } response.setStatus(status); return mv; }
From source file:edu.washington.iam.registry.ws.RelyingPartyController.java
@RequestMapping(value = "/rp", method = RequestMethod.DELETE) public ModelAndView deleteRelyingParty(@RequestParam(value = "id", required = true) String id, @RequestParam(value = "mdid", required = true) String mdid, @RequestParam(value = "role", required = false) String role, @RequestParam(value = "xsrf", required = false) String paramXsrf, InputStream in, HttpServletRequest request, HttpServletResponse response) { RPSession session = processRequestInfo(request, response, false); if (session == null) return (emptyMV()); log.info("DELETE for: " + id); int status = 200; if (session.isBrowser && !(paramXsrf != null && paramXsrf.equals(session.xsrfCode))) { log.info("got invalid xsrf=" + paramXsrf + ", expected+" + session.xsrfCode); return emptyMV("invalid session (xsrf)"); }//from w w w. j a v a 2 s. c om ModelAndView mv = emptyMV("OK dokey delete rp"); try { if (!userCanEdit(session, id)) { status = 401; mv.addObject("alert", "You are not the owner."); } else { status = proxyManager.removeRelyingParty(id); status = filterPolicyManager.removeEditableRelyingParty(id); status = rpManager.removeRelyingParty(id, mdid); } } catch (FilterPolicyException e) { mv.addObject("alert", "delete of filter policy failed:\n" + e.getCause()); response.setStatus(500); return mv; } catch (DNSVerifyException e) { mv.addObject("alert", "Could not verify ownership:\n" + e.getCause()); response.setStatus(500); return mv; } SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(mailTo); msg.setText( "User '" + session.remoteUser + "' deleted metadata for '" + id + "'.\nRequest status: " + status); try { this.mailSender.send(msg); } catch (MailException ex) { log.error("sending mail: " + ex.getMessage()); } response.setStatus(status); return mv; }
From source file:edu.washington.iam.registry.ws.RelyingPartyController.java
@RequestMapping(value = "/rp/attr", method = RequestMethod.PUT) public ModelAndView putRelyingPartyAttributes(@RequestParam(value = "id", required = true) String id, @RequestParam(value = "policyId", required = true) String policyId, @RequestParam(value = "xsrf", required = false) String paramXsrf, InputStream in, HttpServletRequest request, HttpServletResponse response) { RPSession session = processRequestInfo(request, response, false); if (session == null) return (emptyMV()); log.info("PUT update attrs for " + id + " in " + policyId); int status = 200; /**//from ww w. j a va 2 s .co m if (session.isBrowser && !(paramXsrf!=null && paramXsrf.equals(session.xsrfCode))) { log.info("got invalid xsrf=" + paramXsrf + ", expected+" + session.xsrfCode); return emptyMV("invalid session (xsrf)"); } **/ ModelAndView mv = emptyMV("OK dokey"); if (!session.isAdmin) { status = 401; mv.addObject("alert", "You are not permitted to update attriubtes."); response.setStatus(status); return mv; } Document doc = null; try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); doc = builder.parse(in); } catch (Exception e) { log.info("parse error: " + e); status = 400; mv.addObject("alert", "The posted document was not valid:\n" + e); } if (doc != null) { try { filterPolicyManager.updateRelyingParty(policyId, doc); status = 200; } catch (FilterPolicyException e) { status = 400; mv.addObject("alert", "Update of the entity failed:" + e); } } SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(mailTo); String act = "updated"; if (status == 201) act = "created"; msg.setSubject("Service provider attributes " + act + " by " + session.remoteUser); msg.setText("User '" + session.remoteUser + "' " + act + " attributes for '" + id + "'.\nRequest status: " + status + "\n"); try { this.mailSender.send(msg); } catch (MailException ex) { log.error("sending mail: " + ex.getMessage()); } response.setStatus(status); return mv; }
From source file:edu.washington.iam.registry.ws.RelyingPartyController.java
@RequestMapping(value = "/rp/attrReq", method = RequestMethod.PUT) public ModelAndView putRelyingPartyAttrReq(@RequestParam(value = "id", required = true) String id, InputStream in, HttpServletRequest request, HttpServletResponse response) { RPSession session = processRequestInfo(request, response, false); if (session == null) return (emptyMV()); log.info("PUT request for: " + id); int status = 200; ModelAndView mv = emptyMV("OK dokey"); try {// w ww. ja v a2 s .c o m if (!userCanEdit(session, id)) { status = 401; mv.addObject("alert", "You are not an owner of that entity."); } } catch (DNSVerifyException e) { mv.addObject("alert", "Could not verify ownership:\n" + e.getCause()); response.setStatus(500); return mv; } Document doc = null; try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); doc = builder.parse(in); } catch (Exception e) { log.info("parse error: " + e); status = 400; mv.addObject("alert", "The posted document was not valid:\n" + e); } if (doc != null) { StringBuffer txt = new StringBuffer( "[ Assign to Identity and Access Management. ]\n\nEntity Id: " + id + "\n"); txt.append("User: " + session.remoteUser + "\n\nRequesting:\n"); List<Element> attrs = XMLHelper.getElementsByName(doc.getDocumentElement(), "Add"); log.debug(attrs.size() + " adds"); for (int i = 0; i < attrs.size(); i++) txt.append(" Add new attribute: " + attrs.get(i).getAttribute("id") + "\n\n"); attrs = XMLHelper.getElementsByName(doc.getDocumentElement(), "Drop"); log.debug(attrs.size() + " drops"); for (int i = 0; i < attrs.size(); i++) txt.append(" Drop existing attribute: " + attrs.get(i).getAttribute("id") + "\n\n"); Element mele = XMLHelper.getElementByName(doc.getDocumentElement(), "Comments"); if (mele != null) txt.append("\nComment:\n\n" + mele.getTextContent() + "\n\n"); txt.append("Quick link:\n\n " + spRegistryUrl + "#a" + id + "\n"); SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); /* production to RT system */ msg.setTo(requestMailTo); msg.setSubject("IdP attribute request for " + id); msg.setFrom(session.remoteUser + "@uw.edu"); msg.setText(txt.toString()); try { this.mailSender.send(msg); } catch (MailException ex) { log.error("sending mail: " + ex.getMessage()); status = 500; } } response.setStatus(status); return mv; }
From source file:edu.washington.iam.registry.ws.RelyingPartyController.java
@RequestMapping(value = "/rp/proxy", method = RequestMethod.PUT) public ModelAndView putRelyingPartyAttributesZ(@RequestParam(value = "id", required = true) String id, @RequestParam(value = "role", required = false) String role, @RequestParam(value = "xsrf", required = false) String paramXsrf, InputStream in, HttpServletRequest request, HttpServletResponse response) { RPSession session = processRequestInfo(request, response, false); if (session == null) return (emptyMV()); log.info("PUT update proxy for " + id); int status = 200; if (session.isBrowser && !(paramXsrf != null && paramXsrf.equals(session.xsrfCode))) { log.info("got invalid xsrf=" + paramXsrf + ", expected+" + session.xsrfCode); return emptyMV("invalid session (xsrf)"); }/* w w w .j ava 2 s . c o m*/ ModelAndView mv = emptyMV("OK dokey"); try { if (!userCanEdit(session, id)) { status = 401; mv.addObject("alert", "You are not an owner of that entity."); response.setStatus(status); return mv; } } catch (DNSVerifyException e) { mv.addObject("alert", "Could not verify ownership:\n" + e.getCause()); response.setStatus(500); return mv; } Document doc = null; try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); doc = builder.parse(in); } catch (Exception e) { log.info("parse error: " + e); status = 400; mv.addObject("alert", "The posted document was not valid:\n" + e); } if (doc != null) { try { List<Element> eles = XMLHelper.getElementsByName(doc.getDocumentElement(), "Proxy"); if (eles.size() != 1) throw new ProxyException("proxy xml must contain one element"); Element pxe = eles.get(0); Proxy newproxy = new Proxy(pxe); if (!newproxy.getEntityId().equals(id)) throw new ProxyException("post doesn't match qs id"); proxyManager.updateProxy(newproxy); status = 200; } catch (ProxyException e) { status = 400; mv.addObject("alert", "Update of the entity failed:" + e); } } SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(mailTo); String act = "updated"; if (status == 201) act = "created"; msg.setSubject("Service provider proxy info " + act + " by " + session.remoteUser); msg.setText("User '" + session.remoteUser + "' " + act + " proxy info '" + id + "'.\nRequest status: " + status + "\n"); try { this.mailSender.send(msg); } catch (MailException ex) { log.error("sending mail: " + ex.getMessage()); } response.setStatus(status); return mv; }
From source file:cz.zcu.kiv.eegdatabase.data.service.SpringJavaMailService.java
@Override public boolean sendForgottenPasswordMail(String email, String plainPassword) { log.debug("Creating new mail object"); SimpleMailMessage mail = new SimpleMailMessage(mailMessage); log.debug("Composing e-mail - TO: " + email); String subject = mail.getSubject() + " - Password reset"; log.debug("Composing e-mail - SUBJECT: " + subject); mail.setSubject(subject);//from w ww . j a va 2 s . c o m String text = "Your password for EEGbase portal was reset. Your new password (within brackets) is [" + plainPassword + "]\n\n" + "Please change the password after logging into system."; log.debug("Composing e-mail - TEXT: " + text); mail.setText(text); return sendEmail(email, mail.getSubject(), mail.getText()); }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.myaccount.ApplyForWritingPermissionController.java
@Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { log.debug("Processing the form"); ApplyForWritingPermissionCommand afwpc = (ApplyForWritingPermissionCommand) command; log.debug("Loading Person object of actual logged user from database"); Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); log.debug("Composing e-mail message"); SimpleMailMessage mail = new SimpleMailMessage(mailMessage); mail.setFrom(user.getEmail());// w w w. j ava 2 s . c om log.debug("Loading list of supervisors"); List<Person> supervisors = personDao.getSupervisors(); String[] emails = new String[supervisors.size()]; int i = 0; for (Person supervisor : supervisors) { emails[i++] = supervisor.getEmail(); } mail.setTo(emails); log.debug("Setting subject to e-mail message"); mail.setSubject(mail.getSubject() + " - Write permission request from user " + user.getUsername()); String messageBody = "User " + user.getUsername() + " has requested permission for adding data into EEGbase system.\n" + "Reason is: " + afwpc.getReason() + "\n" + "Use the address below to grant the write permission.\n"; String linkAddress = "http://" + request.getLocalAddr() + ":" + request.getLocalPort() + request.getContextPath() + "/system/grant-permission.html?id=" + user.getPersonId(); log.debug("Address is: " + linkAddress); messageBody += linkAddress; mail.setText(messageBody); String mavName = ""; try { log.debug("Sending message"); mailSender.send(mail); log.debug("Mail was sent"); mavName = getSuccessView(); } catch (MailException e) { log.debug("Mail was not sent"); mavName = getFailView(); } log.debug("Returning MAV"); ModelAndView mav = new ModelAndView(mavName); return mav; }