List of usage examples for org.springframework.mail SimpleMailMessage SimpleMailMessage
public SimpleMailMessage(SimpleMailMessage original)
From source file:cz.zcu.kiv.eegdatabase.logic.controller.root.ForgottenPasswordController.java
@Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { ForgottenPasswordCommand fpc = (ForgottenPasswordCommand) command; Person user = personDao.getPerson(fpc.getUsername()); log.debug("Creating new mail object"); SimpleMailMessage mail = new SimpleMailMessage(mailMessage); String recipient = user.getEmail(); log.debug("Composing e-mail - TO: " + recipient); mail.setTo(recipient);// w w w.jav a 2s .c o m String subject = mail.getSubject() + " - Password reset"; log.debug("Composing e-mail - SUBJECT: " + subject); mail.setSubject(subject); String password = ControllerUtils.getRandomPassword(); String text = "Your password for EEGbase portal was reset. Your new password (within brackets) is [" + password + "]\n\n" + "Please change the password after logging into system."; log.debug("Composing e-mail - TEXT: " + text); mail.setText(text); String mavName = getSuccessView(); try { log.debug("Sending e-mail message"); mailSender.send(mail); log.debug("E-mail message sent successfully"); log.debug("Updating new password into database"); user.setPassword(new BCryptPasswordEncoder().encode(password)); personDao.update(user); log.debug("Password updated"); } catch (MailException e) { log.debug("E-mail message was NOT sent"); log.debug("Password was NOT changed"); mavName = getFailedView(); } log.debug("Returning MAV"); ModelAndView mav = new ModelAndView(mavName); return mav; }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.root.WriteRequestsListController.java
/** * Sends e-mail with granting message or rejecting message to the recipient * * @param recipient E-mail address of the recipient * @param grant If <code>true</code>, granting message will be sent, * if <code>false</code>, rejecting message will be sent *///from w ww .j a v a 2 s . c o m private boolean sendEmail(String recipient, boolean grant) { log.debug("Sending e-mail"); SimpleMailMessage mail = new SimpleMailMessage(mailMessage); mail.setTo(recipient); log.debug("Setting the parameters of the e-mail message"); String subject = ""; String text = ""; if (grant) { subject = mail.getSubject() + " - Write permission granted"; text = "Congratulation, the write permission for the EEGbase portal was granted. You can now submit your data. Thank you for your interest."; } else { subject = mail.getSubject() + " - Write permission rejected"; text = "We are sorry, but the write permission for the EEGbase portal was rejected. You can apply again, try to better explain your reasons. Thank you."; } mail.setSubject(subject); mail.setText(text); try { log.debug("Sending the e-mail"); mailSender.send(mail); log.debug("E-mail was sent"); return true; } catch (MailException e) { log.debug("E-mail was NOT sent"); return false; } }
From source file:ome.logic.AdminImpl.java
private boolean sendEmail(Experimenter e, String newPassword) { // Create a thread safe "copy" of the template message and customize it SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setSubject("OMERO - Reset password"); msg.setTo(e.getEmail());// w w w . j a va2 s .co m msg.setText("Dear " + e.getFirstName() + " " + e.getLastName() + " (" + e.getOmeName() + ")" + " your new password is: " + newPassword); try { this.mailSender.send(msg); } catch (Exception ex) { throw new RuntimeException("Exception: " + ex.getMessage() + ". " + "Password was not changed because email could not be sent " + "to the " + e.getOmeName() + ". Please turn on the debuge " + "mode in omero.properties by the: omero.resetpassword.mail.debug=true"); } return true; }
From source file:org.beangle.emsapp.security.action.MyAction.java
/** * ???/*from w w w . j a v a2 s . c om*/ */ public String sendPassword() { String name = get("name"); String email = get("mail"); if (StringUtils.isEmpty(name) || StringUtils.isEmpty(email)) { addActionError("error.parameters.needed"); return (ERROR); } List<User> userList = entityDao.get(User.class, "name", name); User user = null; if (userList.isEmpty()) { return goErrorWithMessage("error.user.notExist"); } else { user = userList.get(0); } if (!StringUtils.equals(email, user.getMail())) { return goErrorWithMessage("error.email.notEqualToOrign"); } else { String longinName = user.getName(); String password = RandomStringUtils.randomNumeric(6); user.setRemark(password); user.setPassword(EncryptUtil.encode(password)); String title = getText("user.password.sendmail.title"); List<Object> values = CollectUtils.newArrayList(); values.add(longinName); values.add(password); String body = getText("user.password.sendmail.body", values); try { SimpleMailMessage msg = new SimpleMailMessage(message); msg.setTo(user.getMail()); msg.setSubject(title); msg.setText(body.toString()); mailSender.send(msg); } catch (Exception e) { e.printStackTrace(); logger.info("reset password error for user:" + user.getName() + " with email :" + user.getMail()); return goErrorWithMessage("error.email.sendError"); } } entityDao.saveOrUpdate(user); return forward("sendResult"); }
From source file:org.encuestame.business.service.MailService.java
@Deprecated public void send(final String to, final String subject, final String text) throws MailSendException { SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setFrom(getNoEmailResponse());//from ww w . j a va 2 s .c o m msg.setTo(to); // msg.setCc(); msg.setText(text); msg.setSubject(buildSubject(subject)); mailSender.send(msg); //log.debug("mail.succesful"); }
From source file:org.encuestame.business.service.MailService.java
/** * Send invitation./*from w w w. j a v a2 s .c o m*/ * @param to email to send * @param code code of password * @throws MailSendException mail exception. */ public void sendInvitation(final String to, final String code) throws MailSendException { final SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setFrom(getNoEmailResponse()); msg.setTo(to); msg.setText("<h1>Invitation to Encuestame</h1><p>Please confirm" + " this invitation <a>http://www.encuesta.me/cod/" + code + "</a>"); msg.setSubject(buildSubject("test")); try { mailSender.send(msg); } catch (Exception e) { log.error("Error on send email " + e.getMessage()); } }
From source file:org.encuestame.business.service.MailService.java
/** * Delete notification.// w ww. j ava2 s . c om * @param to mail to send * @param body body of message * @throws MailSendException exception */ public void sendDeleteNotification(final String to, final String body) throws MailSendException { SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setFrom(getNoEmailResponse()); msg.setTo(to); msg.setText(body); msg.setSubject( buildSubject(getMessageProperties("email.message.delete.invitation", buildCurrentLocale(), null))); mailSender.send(msg); }
From source file:org.gbif.portal.service.impl.LogManagerImpl.java
/** * Sends a log message to the appropriate recipient * //from www. j av a2 s.co m * TODO Should really make use of velocity templating * * @param message GbifLogMessage */ protected void sendFeedbackMessage(GbifLogMessage message, User user, String url) { // for safety if (user == null) { return; } List<String> toEmailAddresses = new ArrayList<String>(); toEmailAddresses.add("sib+dataportal@humboldt.org.co"); List<String> ccEmailAddresses = new ArrayList<String>(); if (message.getDataResourceId() != 0) { String dataResourceKey = new Long(message.getDataResourceId()).toString(); List<DataResourceAgentDTO> agents = dataResourceManager.getAgentsForDataResource(dataResourceKey); if (agents != null) { for (DataResourceAgentDTO agent : agents) { if (agent.getAgentType() == AgentType.DATAADMINISTRATOR.getValue()) { toEmailAddresses.add(processEmail(agent.getAgentEmail())); } else { ccEmailAddresses.add(processEmail(agent.getAgentEmail())); } } if (toEmailAddresses.size() == 0 && ccEmailAddresses.size() > 0) { toEmailAddresses = ccEmailAddresses; ccEmailAddresses = new ArrayList<String>(); } } } if (toEmailAddresses.size() == 0 && message.getDataProviderId() != 0) { String dataProviderKey = new Long(message.getDataProviderId()).toString(); List<DataProviderAgentDTO> agents = dataResourceManager.getAgentsForDataProvider(dataProviderKey); if (agents != null) { for (DataProviderAgentDTO agent : agents) { if (agent.getAgentType() == AgentType.DATAADMINISTRATOR.getValue()) { toEmailAddresses.add(processEmail(agent.getAgentEmail())); } else { ccEmailAddresses.add(processEmail(agent.getAgentEmail())); } } if (toEmailAddresses.size() == 0 && ccEmailAddresses.size() > 0) { toEmailAddresses = ccEmailAddresses; ccEmailAddresses = new ArrayList<String>(); } } } if (toEmailAddresses.size() != 0) { ccEmailAddresses.addAll(portalEmailAddresses); ccEmailAddresses.removeAll(toEmailAddresses); SimpleMailMessage providerMessage = new SimpleMailMessage(providerTemplateMessage); providerMessage.setTo(toEmailAddresses.toArray(new String[toEmailAddresses.size()])); //user that submitted feedback should also be CCed if (user.getEmail() != null) { ccEmailAddresses.add(processEmail(user.getEmail())); } providerMessage.setCc(ccEmailAddresses.toArray(new String[ccEmailAddresses.size()])); // TODO - NLS and portal URL StringBuffer subjectBuffer = new StringBuffer(); SimpleMailMessage userMessage = new SimpleMailMessage(userTemplateMessage); userMessage.setTo(user.getEmail()); subjectBuffer.append("Comentarios desde el Portal de Datos del SIB Colombia - "); StringBuffer textBuffer = new StringBuffer(); textBuffer.append( "El siguiente mensaje ha sido enviado a travs del Portal del Datos del SIB Colombia.\n\n"); if (user != null) { textBuffer.append(" Usuario: "); textBuffer.append(user.getName()); textBuffer.append(" ("); textBuffer.append(user.getEmail()); textBuffer.append(")\n\n"); } if (message.getDataProviderId() != null && message.getDataProviderId() != 0) { try { DataProviderDTO dto = dataResourceManager .getDataProviderFor(new Long(message.getDataProviderId()).toString()); textBuffer.append(" Publicador de datos: "); textBuffer.append(dto.getName()); textBuffer.append("\n"); String portalUrl = " URL en el portal: " + url + "/datasets/provider/"; //textBuffer.append(" Portal URL: http://data.gbif.org/datasets/provider/"); textBuffer.append(portalUrl); textBuffer.append(dto.getKey()); textBuffer.append("\n\n"); } catch (Exception e) { // ignore } } if (message.getDataResourceId() != null && message.getDataResourceId() != 0) { try { DataResourceDTO dto = dataResourceManager .getDataResourceFor(new Long(message.getDataResourceId()).toString()); textBuffer.append(" Conjunto de datos: "); textBuffer.append(dto.getName()); textBuffer.append("\n"); String portalUrl = " URL en el portal: " + url + "/datasets/resource/"; //textBuffer.append(" Portal URL: http://data.gbif.org/datasets/resource/"); textBuffer.append(portalUrl); textBuffer.append(dto.getKey()); textBuffer.append("\n\n"); } catch (Exception e) { // ignore } } if (message.getOccurrenceId() != null && message.getOccurrenceId() != 0) { try { OccurrenceRecordDTO dto = occurrenceManager .getOccurrenceRecordFor(new Long(message.getOccurrenceId()).toString()); subjectBuffer.append("catalogue number: "); subjectBuffer.append(dto.getCatalogueNumber()); subjectBuffer.append(" "); textBuffer.append(" Occurrence record: "); textBuffer.append(dto.getInstitutionCode()); textBuffer.append(" / "); textBuffer.append(dto.getCollectionCode()); textBuffer.append(" / "); textBuffer.append(dto.getCatalogueNumber()); textBuffer.append("\n"); String portalUrl = " URL en el portal: " + url + "/occurrences/"; //textBuffer.append(" Portal URL: http://data.gbif.org/occurrences/"); textBuffer.append(portalUrl); textBuffer.append(dto.getKey()); textBuffer.append("\n\n"); } catch (Exception e) { // ignore } } if (message.getTaxonConceptId() != null && message.getTaxonConceptId() != 0) { try { TaxonConceptDTO dto = taxonomyManager .getTaxonConceptFor(new Long(message.getTaxonConceptId()).toString()); subjectBuffer.append("taxon: "); subjectBuffer.append(dto.getTaxonName()); textBuffer.append(" Taxon: "); textBuffer.append(dto.getTaxonName()); textBuffer.append("\n"); String portalUrl = " URL en el portal: " + url + "/species/"; //textBuffer.append(" Portal URL: http://data.gbif.org/species/"); textBuffer.append(portalUrl); textBuffer.append(dto.getKey()); textBuffer.append("\n\n"); } catch (Exception e) { // ignore } } textBuffer.append(message.getMessage()); providerMessage.setSubject(subjectBuffer.toString()); providerMessage.setText(textBuffer.toString()); userMessage.setSubject(subjectBuffer.toString()); userMessage.setText("Gracias por su comentario. El mensaje ha sido" + " enviado en su nombre, al publicador de datos apropiado.\n\n"); try { mailSender.send(providerMessage); mailSender.send(userMessage); } catch (MailException e) { // simply log it and go on... logger.error("Couldn't send message", e); } } }
From source file:org.gbif.portal.service.impl.LogManagerImpl.java
/** * Sends a verification message to the User given * // ww w. jav a 2s .com * TODO Should really make use of velocity templating * * @param user to send to */ protected void sendVerificationMessage(User user, String url) { if (user != null) { SimpleMailMessage verificationMessage = new SimpleMailMessage(userTemplateMessage); verificationMessage.setTo(user.getEmail()); verificationMessage.setSubject( "Confirme la direccin de correo electrnico para el Portal de Datos del SIB Colombia "); // todo verificationMessage.setText( "Por favor visite el siguiente enlace para confirmar su direccin de correo electrnico:\n" + url + "/feedback/verification/" + user.getId() + "/" + UserUtils.getCodeFor(user.getName(), user.getEmail())); try { mailSender.send(verificationMessage); } catch (MailException e) { // simply log it and go on... logger.error("Couldn't send message", e); } } }
From source file:org.gbif.portal.web.controller.registration.RegistrationController.java
/** * Forgotten password./*from w w w . j av a 2 s.c om*/ * * @param request * @param response * @return * @throws Exception */ public ModelAndView forgottenPassword(HttpServletRequest request, HttpServletResponse response) throws Exception { if (!isFormSubmission(request)) { ModelAndView mav = new ModelAndView("forgottenPassword"); return mav; } String email = request.getParameter("email"); List<UserLogin> uls = ldapUtils.getUsernamePasswordForEmail(email); if (uls.isEmpty()) { ModelAndView mav = new ModelAndView("forgottenPassword"); mav.addObject("email", email); mav.addObject("unrecognised", true); return mav; } for (UserLogin ul : uls) { // reset password String newPassword = generatePassword(ul.getUsername()); ul.setPassword(newPassword); ldapUtils.updateUser(ul); // send verification email SimpleMailMessage verificationMessage = new SimpleMailMessage(userTemplateMessage); verificationMessage.setTo(email); String encryptedPassword = passwordUtils.encryptPassword(ul.getPassword(), true); verificationMessage.setSubject("Details for GBIF Data Portal"); verificationMessage.setText("Please click here to login:\n\n" + "http://" + request.getHeader("host") + request.getContextPath() + "/register/" + "?u=" + ul.getUsername() + "&p=" + encryptedPassword + "\n\nUsername: " + ul.getUsername() + "\nPassword: " + ul.getPassword()); try { mailSender.send(verificationMessage); } catch (MailException e) { // simply log it and go on... logger.error("Couldn't send message", e); ModelAndView mav = new ModelAndView("emailDetailsFailureView"); mav.addObject("email", email); return mav; } } ModelAndView mav = new ModelAndView("emailDetailsSuccessView"); mav.addObject("email", email); return mav; }