List of usage examples for org.springframework.mail SimpleMailMessage setText
@Override public void setText(String text)
From source file:org.shredzone.cilla.service.notification.NotificationServiceImpl.java
/** * Send a {@link Notification} to a single {@link NotificationTarget}. * <p>/* w w w. ja va 2s.c o m*/ * For the receiver's locale, the appropriate template is opened, it's placeholders * filled with the notification parameters, and the message sent to the target's * mail address. * * @param target * {@link NotificationTarget} to send to * @param notification * {@link Notification} to send */ private void sendToTarget(NotificationTarget target, Notification notification) throws CillaServiceException { try { Template template = freemarkerConfiguration.getTemplate(notification.getType() + ".ftl", target.getLocale()); StringWriter out = new StringWriter(); Environment env = template.createProcessingEnvironment(notification.getAttributes(), out, null); env.process(); out.close(); TemplateModel subjectTm = env.getVariable("subject"); SimpleMailMessage msg = new SimpleMailMessage(); msg.setFrom(sender); msg.setTo(target.getMail()); msg.setSubject(subjectTm != null ? subjectTm.toString() : ""); msg.setText(out.toString()); mailSender.send(msg); } catch (IOException | TemplateException ex) { log.error("Failed to process template ", ex); throw new CillaServiceException("Could not process template", ex); } }
From source file:me.j360.base.service.common.SimpleMailService.java
public void send(Email email) { SimpleMailMessage msg = new SimpleMailMessage(); msg.setFrom("?<system@smart-sales.cn>"); msg.setTo(email.getAccount());//from w ww. j ava2 s .c o m msg.setSubject(email.getSubject()); msg.setText(email.getBody()); try { mailSender.send(msg); /*if (logger.isInfoEnabled()) { logger.info("??{}", StringUtils.join(msg.getTo(), ",")); }*/ } catch (Exception e) { //logger.error("??", e); } }
From source file:org.tsm.concharto.lab.LabJavaMail.java
private void sendConfirmationEmail(User user) { //mailSender.setHost("skipper"); SimpleMailMessage message = new SimpleMailMessage(); message.setTo(user.getEmail());//ww w . j av a 2 s . c o m String messageText = StringUtils.replace(WELCOME_MESSAGE, PARAM_NAME, user.getUsername()); message.setText(messageText); message.setSubject(WELCOME_SUBJECT); message.setFrom("<Concharto Notifications> notify@concharto.com"); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); MimeMessage mimeMessage = mailSender.createMimeMessage(); InternetAddress from = new InternetAddress(); from.setAddress("notify@concharto.com"); InternetAddress to = new InternetAddress(); to.setAddress(user.getEmail()); try { from.setPersonal("Concharto Notifications"); mimeMessage.addRecipient(Message.RecipientType.TO, to); mimeMessage.setSubject(WELCOME_SUBJECT); mimeMessage.setText(messageText); mimeMessage.setFrom(from); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } mailSender.setHost("localhost"); mailSender.send(mimeMessage); /* Confirm your registration with Concharto Hello sanmi, Welcome to the Concharto community! Please click on this link to confirm your registration: http://www.concharto.com/member/confirm.htm?id=:confirmation You can find out more about us at http://wiki.concharto.com/wiki/About. If you were not expecting this email, just ignore it, no further action is required to terminate the request. */ }
From source file:com.mycompany.capstone.dao.QuoteDaoDbImpl.java
@Override public Quote create(Quote quote) { jdbcTemplate.update(SQL_INSERT_QUOTE, quote.getFirstName(), quote.getLastName(), quote.getEmail(), quote.getYear(), quote.getSelectedMake(), quote.getSelectedModel(), quote.getDescription()); Integer id = jdbcTemplate.queryForObject("SELECT LAST_INSERT_ID()", Integer.class); quote.setId(id);/*from w w w . ja v a2s . com*/ Properties props = (Properties) System.getProperties().clone(); props.put("mail.smtp.host", "host"); props.setProperty("mail.smtp.port", "587"); props.put("mail.smtp.auth", true); //Bypass the SSL authentication props.put("mail.smtp.ssl.enable", false); props.put("mail.smtp.starttls.enable", false); SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo("bennettglob@gmail.com"); // msg.setRecipients(Message.RecipientType.TO, ("bennettglob@gmail.com" + quote.getEmail())); msg.setText("test"); try { this.mailSender.send(msg); } catch (MailException ex) { // simply log it and go on... System.err.println(ex.getMessage()); } return quote; }
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);//from w ww. j a va2 s. co m msg.setSubject("??"); msg.setText("?" + authcode); try { mailSender.send(msg); /*if (logger.isInfoEnabled()) { logger.info("??{}", StringUtils.join(msg.getTo(), ",")); }*/ } catch (Exception e) { //logger.error("??", e); } }
From source file:de.codecentric.boot.admin.notify.MailNotifierTest.java
@Test public void test_onApplicationEvent() { notifier.notify(new ClientApplicationStatusChangedEvent( Application.create("App").withId("-id-").withHealthUrl("http://health").build(), StatusInfo.ofDown(), StatusInfo.ofUp())); SimpleMailMessage expected = new SimpleMailMessage(); expected.setTo(new String[] { "foo@bar.com" }); expected.setCc(new String[] { "bar@foo.com" }); expected.setFrom("SBA <no-reply@example.com>"); expected.setText("App (-id-)\nstatus changed from DOWN to UP\n\nhttp://health"); expected.setSubject("-id- is UP"); verify(sender).send(eq(expected));/*ww w .j a va 2s . co m*/ }
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;//w w w . jav a 2s . 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:com.springsource.greenhouse.invite.mail.AsyncMailInviteService.java
private SimpleMailMessage createInviteMailMessage(Invitee to, String text) { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom("Greenhouse <noreply@springsource.com>"); mailMessage.setTo(to.getEmail());/*from w ww . j a va 2 s . com*/ mailMessage.setSubject("Your Greenhouse Invitation"); mailMessage.setText(text); return mailMessage; }
From source file:com.miserablemind.butter.domain.service.email.EmailService.java
/** * Sends a plain text message. Uses {@link EmailMessage#getPlainTextBody()} * * @param emailMessage prepared message object to be sent. Usually prepared by {@link EmailManager} *//*from ww w . j a va2s . com*/ public void sendTextMail(EmailMessage emailMessage) { SimpleMailMessage textMessage = new SimpleMailMessage(); textMessage.setFrom(emailMessage.getFromAddress().getAddress()); textMessage.setTo(emailMessage.getToEmail()); textMessage.setSubject(emailMessage.getSubject()); textMessage.setText(emailMessage.getPlainTextBody()); try { this.mailSender.send(textMessage); } catch (MailException e) { logger.error("Email Service Exception Send Text Mail: " + e.getMessage(), e); } }
From source file:com.mycompany.spring.batch.mail.demo.batch.SampleBatchApplication.java
@Bean public ItemProcessor processor() { ItemProcessor processor = new ItemProcessor() { @Override/*from w w w. j a v a 2 s. c o m*/ public SimpleMailMessage process(Object item) throws Exception { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("root@localhost.localdomain"); message.setTo("c7@localhost.localdomain"); message.setSubject(item.toString()); message.setSentDate(new Date()); message.setText("Hello " + item.toString()); System.out.println("Sending message with subject: " + item); return message; } }; return processor; }