List of usage examples for org.springframework.mail SimpleMailMessage setTo
@Override public void setTo(String... to)
From source file:me.j360.base.service.common.SimpleMailService.java
public void sendRegisterAuthCodeMail(String username, String authcode) { SimpleMailMessage msg = new SimpleMailMessage(); msg.setFrom("?<system@smart-sales.cn>"); msg.setTo(username); msg.setSubject("??"); msg.setText("?" + authcode); try {//from w w w. jav a2 s. co m mailSender.send(msg); /*if (logger.isInfoEnabled()) { logger.info("??{}", StringUtils.join(msg.getTo(), ",")); }*/ } catch (Exception e) { //logger.error("??", e); } }
From source file:ar.com.zauber.commons.message.impl.mail.SimpleEmailNotificationStrategy.java
/** @see NotificationStrategy#execute(NotificationAddress[], Message) */ //CHECKSTYLE:ALL:OFF public void execute(final NotificationAddress[] addresses, final Message message) { final SimpleMailMessage mail = new SimpleMailMessage(); mail.setFrom(getFromAddress().getEmailStr()); mail.setTo(getEmailAddresses(addresses)); mail.setReplyTo(getEmailAddress(message.getReplyToAddress())); mail.setSubject(message.getSubject()); mail.setText(message.getContent());/* ww w . j av a2s . c om*/ mailSender.send(mail); }
From source file:me.j360.base.service.common.SimpleMailService.java
/** * ??.// w w w . j av a 2s. c om */ public void sendNotificationMail(String userName) { SimpleMailMessage msg = new SimpleMailMessage(); msg.setFrom("?<system@smart-sales.cn>"); msg.setTo("xuminwlt2008@163.com"); msg.setSubject("?"); //id String url = "http://www.smart-sales.cn/smartsales/com/email.action?keyId=1"; // ???? String content = String.format(textTemplate, userName, new Date(), url); msg.setText(content); /*try { mailSender.send(msg); if (logger.isInfoEnabled()) { logger.info("??{}", StringUtils.join(msg.getTo(), ",")); } } catch (Exception e) { logger.error("??", e); }*/ }
From source file:csns.web.controller.UserController.java
@RequestMapping(value = "/resetPassword", method = RequestMethod.POST) public String resetPassword(HttpServletRequest request, ModelMap models) { String username = request.getParameter("username"); String cin = request.getParameter("cin"); String email = request.getParameter("email"); User user = null;//from ww w . ja v a2 s. c o m if (StringUtils.hasText(cin)) user = userDao.getUserByCin(cin); else if (StringUtils.hasText(username)) user = userDao.getUserByUsername(username); else if (StringUtils.hasText(email)) user = userDao.getUserByEmail(email); models.put("backUrl", defaultUrls.homeUrl(request)); if (user == null) { models.put("message", "error.reset.password.user.not.found"); return "error"; } if (user.isTemporary()) { models.put("message", "error.reset.password.temporary.user"); return "error"; } String newPassword = "" + (int) (Math.random() * 100000000); user.setPassword(passwordEncoder.encodePassword(newPassword, null)); userDao.saveUser(user); logger.info("Reset password for " + user.getUsername()); Map<String, Object> vModels = new HashMap<String, Object>(); vModels.put("username", user.getUsername()); vModels.put("password", newPassword); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "email.resetPassword.vm", appEncoding, vModels); SimpleMailMessage message = new SimpleMailMessage(); message.setTo(user.getPrimaryEmail()); message.setFrom(appEmail); message.setText(text); try { mailSender.send(message); logger.info("Password reset message sent to " + user.getPrimaryEmail()); } catch (MailException e) { logger.error(e.getMessage()); models.put("message", "error.reset.password.email.failure"); return "error"; } models.put("message", "status.reset.password"); return "status"; }
From source file:org.openxdata.server.servlet.ResetPasswordServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(this.getServletContext()); mailSender = (org.springframework.mail.javamail.JavaMailSenderImpl) ctx.getBean("mailSender"); userService = (UserService) ctx.getBean("userService"); userDetailsService = (UserDetailsService) ctx.getBean("userDetailsService"); messageSource = (ResourceBundleMessageSource) ctx.getBean("messageSource"); userLocale = new Locale((String) request.getSession().getAttribute("locale")); //new AcceptHeaderLocaleResolver().resolveLocale(request); log.debug("userLocale=" + userLocale.getLanguage()); String email = request.getParameter("email"); if (email == null) { //ajax response reference text out.println("noEmailSuppliedError"); }/* w w w .j a v a2s. com*/ try { User user = userService.findUserByEmail(email); /* * Valid User with the correct e-mail. */ insertUserInSecurityContext(user); // this is so that it is possible to reset their password (security checks) Properties props = propertyPlaceholder.getResolvedProps(); String from = props.getProperty("mailSender.from"); try { //Reset the User password and send an email userService.resetPassword(user, 6); SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(email); msg.setSubject(messageSource.getMessage("resetPasswordEmailSubject", new Object[] { user.getFullName() }, userLocale)); msg.setText(messageSource.getMessage("resetPasswordEmail", new Object[] { user.getName(), user.getClearTextPassword() }, userLocale)); msg.setFrom(from); try { mailSender.send(msg); //ajax response reference text out.println("passwordResetSuccessful"); } catch (MailException ex) { log.error("Error while sending an email to the user " + user.getName() + " in order to reset their password.", ex); log.error("Password reset email:" + msg.toString()); //ajax response reference text out.println("emailSendError"); } } catch (Exception e) { log.error("Error while resetting the user " + user.getName() + "'s password", e); //ajax response reference text out.println("passwordResetError"); } } catch (UserNotFoundException userNotFound) { /* * Invalid User or incorrect Email. */ //ajax response reference text out.println("validationError"); } }
From source file:net.triptech.metahive.service.OpenIdAuthenticationFailureHandler.java
/** * Send a notification email.//from w w w. j a v a 2 s . c o m * * @param newPerson the new person */ private void sendNotificationEmail(final Person newPerson) { SimpleMailMessage message = new SimpleMailMessage(); message.setTo("paintbuoy@gmail.com"); message.setFrom("david.harrison@stress-free.co.nz"); StringBuilder subject = new StringBuilder(); subject.append("Metahive: New user '"); subject.append(newPerson.getFormattedName()); subject.append("' ("); subject.append(newPerson.getEmailAddress()); subject.append(") registered"); StringBuilder body = new StringBuilder(); body.append(newPerson.getFormattedName()); body.append(" ("); body.append(newPerson.getEmailAddress()); body.append(") just registered at the Metahive.\n\n"); body.append("Have a nice day.\n"); message.setSubject(subject.toString()); message.setText(body.toString()); try { emailSenderService.send(message, null); } catch (ServiceException se) { logger.error("Error sending notification email: " + se.getMessage()); } }
From source file:com.gnizr.web.action.user.RequestPasswordReset.java
private boolean sendPasswordResetEmail(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 (getVerifyResetTemplate() == null) { logger.error("RequestPasswordReset: templateMessge bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; }/* ww w. j a v a 2 s . c om*/ String toEmail = user.getEmail(); if (toEmail == null) { logger.error("RequestPasswordReset: the email of user " + user.getUsername() + " is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_EMAIL_UNDEF)); return false; } SimpleMailMessage msg = new SimpleMailMessage(getVerifyResetTemplate()); 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/notifyreset-template.ftl"); text = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate, model); } catch (Exception e) { logger.error("RequestPasswordReset: error creating message template from Freemarker engine"); } msg.setText(text); if (getMailSender() == null) { logger.error("RequestPasswordReset: mailSender bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; } try { getMailSender().send(msg); return true; } catch (Exception e) { logger.error("RequestPasswordReset: send mail error. " + e); addActionError(String.valueOf(ActionErrorCode.ERROR_INTERNAL)); } return false; }
From source file:csns.util.MassMailSender.java
public void send(AbstractMessage message, Subscribable subscribable) { SimpleMailMessage email = new SimpleMailMessage(); email.setSubject(message.getSubject()); email.setText(emailUtils.getText(message)); email.setFrom(message.getAuthor().getPrimaryEmail()); email.setTo(emailUtils.getAppEmail()); send(email, emailUtils.getAddresses(subscribable)); }
From source file:cherry.spring.common.foundation.impl.MessageStoreImpl.java
@Override public SimpleMailMessage getMessage(long messageId) { QMailLog a = new QMailLog("a"); SQLQuery querya = queryDslJdbcOperations.newSqlQuery(); querya.from(a).forUpdate();/*w w w .j av a 2 s .c om*/ querya.where(a.id.eq(messageId)); querya.where(a.mailStatus.eq(FlagCode.FALSE.code())); querya.where(a.deletedFlg.eq(DeletedFlag.NOT_DELETED.code())); Tuple maillog = queryDslJdbcOperations.queryForObject(querya, new QTuple(a.fromAddr, a.subject, a.body)); if (maillog == null) { return null; } QMailRcpt b = new QMailRcpt("b"); SQLQuery queryb = queryDslJdbcOperations.newSqlQuery(); queryb.from(b).where(b.mailId.eq(messageId)).orderBy(b.id.asc()); List<Tuple> mailrcpt = queryDslJdbcOperations.query(queryb, new QTuple(b.rcptType, b.rcptAddr)); if (mailrcpt.isEmpty()) { return null; } List<String> to = new ArrayList<>(); List<String> cc = new ArrayList<>(); List<String> bcc = new ArrayList<>(); for (Tuple rcpt : mailrcpt) { RcptType type = RcptType.valueOf(rcpt.get(b.rcptType)); if (type == RcptType.TO) { to.add(rcpt.get(b.rcptAddr)); } if (type == RcptType.CC) { cc.add(rcpt.get(b.rcptAddr)); } if (type == RcptType.BCC) { bcc.add(rcpt.get(b.rcptAddr)); } } SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(to.toArray(new String[to.size()])); msg.setCc(cc.toArray(new String[cc.size()])); msg.setBcc(bcc.toArray(new String[bcc.size()])); msg.setFrom(maillog.get(a.fromAddr)); msg.setSubject(maillog.get(a.subject)); msg.setText(maillog.get(a.body)); return msg; }
From source file:mx.unam.pixel.controller.UsuarioController.java
public void recuperaContrasena() { List<Usuario> u = usuarioService.findByCorreo(correoRecuperar); if (u != null || u.size() > 0) { //Aqui se envia correo al usuario investigar si se regresaria null o la lista vacia SimpleMailMessage mail = new SimpleMailMessage(); mail.setTo(u.get(0).getCorreo()); mail.setFrom("pixel.is.pruebas@gmail.com"); mail.setSubject("Muffin"); mail.setCc("pixel_developer@gmail.com"); mail.setText("Tu contrasea es :" + u.get(0).getContrasena()); mailSender.send(mail);//from www . ja va 2 s .co m } return; }