List of usage examples for org.springframework.mail SimpleMailMessage setFrom
@Override public void setFrom(String from)
From source file:org.smigo.user.MailHandler.java
public void sendClientMessage(String emailAddress, String subject, String text) { final SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setTo(emailAddress); simpleMailMessage.setFrom(mailSenderUsername); simpleMailMessage.setSubject("Smigo " + subject); simpleMailMessage.setText(text);// w ww .jav a2 s. co m senderExecutor.execute(() -> mailSender.send(simpleMailMessage)); }
From source file:org.smigo.user.MailHandler.java
public void sendAdminNotification(String subject, Object text) { final SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setTo(notifierEmail); simpleMailMessage.setFrom(mailSenderUsername); simpleMailMessage.setSubject("[SMIGO] " + subject); simpleMailMessage.setText(text.toString()); senderExecutor.execute(() -> mailSender.send(simpleMailMessage)); }
From source file:org.smigo.user.MailHandler.java
@PreDestroy public void sendShutdownAdminNotification() { final SimpleMailMessage simpleMailMessage = new SimpleMailMessage(); simpleMailMessage.setTo(notifierEmail); simpleMailMessage.setFrom(mailSenderUsername); simpleMailMessage.setSubject("[SMIGO] Server"); simpleMailMessage.setText("Server shutdown"); mailSender.send(simpleMailMessage);//from w w w.j a v a 2 s. c om }
From source file:com.example.controller.SendEmailController.java
@RequestMapping(method = RequestMethod.POST) public String doSendEmail(HttpServletRequest request, Model model) throws ClassNotFoundException, SQLException { // takes input from e-mail form String recipientAddress = request.getParameter("email"); String subject = "Email PartyChef"; // prints debug info System.out.println("To: " + recipientAddress); // creates a simple e-mail object SimpleMailMessage email = new SimpleMailMessage(); email.setTo(recipientAddress);/* ww w.j av a 2 s .c o m*/ Users u = Database.getEmail(recipientAddress); if (u != null) { email.setFrom("none-reply@PartyChef.com"); email.setSubject(subject); email.setText("PartyChef to : " + u.getName() + "\n\nUsername : " + u.getUsername() + "\n\n" + "Password : " + u.getPassword() + "\n\nBest regards,\nPartyChef team\n"); // sends the e-mail /*com.google.apphosting.api.ApiProxy.Environment env = ApiProxy.getCurrentEnvironment(); env.getAttributes().put("com.google.apphosting.api.ApiProxy.api_deadline_key", 9999 );*/ mailSender.send(email); return "login"; } // forwards to the view named "Result" model.addAttribute("error", "Email is invalid"); return "EmailSend"; }
From source file:csns.web.controller.SectionGradeController.java
private void emailGrade(Enrollment enrollment) { if (enrollment.getGrade() == null || enrollment.isGradeMailed()) return;/*from w w w. j a va 2 s.c o m*/ User instructor = SecurityUtils.getUser(); User student = enrollment.getStudent(); SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(instructor.getEmail()); message.setTo(student.getEmail()); Course course = enrollment.getSection().getCourse(); String subject = course.getCode() + " Grade"; message.setSubject(subject); Map<String, Object> vModels = new HashMap<String, Object>(); vModels.put("grade", enrollment.getGrade().getSymbol()); String comments = enrollment.getComments(); vModels.put("comments", comments != null ? comments : ""); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "email.section.grade.vm", appEncoding, vModels); message.setText(text); try { mailSender.send(message); enrollment.setGradeMailed(true); enrollmentDao.saveEnrollment(enrollment); logger.info(instructor.getUsername() + " sent " + course.getCode() + " grade to " + student.getEmail()); } catch (MailException e) { logger.warn(instructor.getUsername() + " failed to send " + course.getCode() + " grade to " + student.getEmail()); logger.debug(e.getMessage()); } }
From source file:ru.retbansk.utils.scheduled.impl.ReplyManagerSimpleImpl.java
/** * Send an error email of a not valid day report. * // w w w.j av a 2s . c o m * @see org.springframework.mail.SimpleMailMessage * @see org.springframework.mail.javamail.JavaMailSenderImpl * @param dayReport I used DayReport as a parameter to know whom to send */ public void sendError(DayReport dayReport) { SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(dayReport.getPersonId()); msg.setReplyTo(dayReport.getPersonId()); msg.setFrom(user); msg.setSubject("RE: " + (dayReport.getSubject() == null ? "" : dayReport.getSubject())); msg.setText("This is an automated email. Do not reply.\n" + "No valid reports were detected. Check your report.\nExample of valid reports:\n" + "helping Google with Android, in process, 7\nmain job/ in process/1\nnothing actually. done. 3\n"); try { this.mailSender.send(msg); } catch (MailException ex) { logger.error(ex.getMessage()); } }
From source file:ru.retbansk.utils.scheduled.impl.ReplyManagerSimpleImpl.java
/** * Send a confirmation email of a valid day report. * Includes xml readable string of it./* ww w. j a v a 2 s .com*/ * @see org.springframework.mail.SimpleMailMessage * @see org.springframework.mail.javamail.JavaMailSenderImpl */ @Override public void placeReply(Reply reply) throws Exception { SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(reply.getEmailAddress()); msg.setReplyTo(reply.getEmailAddress()); msg.setFrom(user); msg.setSubject("RE: " + (reply.getSubject() == null ? "" : reply.getSubject())); msg.setText("This is an automated email. Do not reply.\n" + "Your day report is recieved and saved ." + " You are allowed to make modifications till 23:59 GMT+3." + " Just send new report, the old one will be deleted.\n" + "Converted report look like:\n" + reply.getXml()); try { this.mailSender.send(msg); } catch (MailException ex) { logger.error(ex.getMessage()); } }
From source file:org.openregistry.core.service.DefaultEmailIdentifierNotificationStrategy.java
public void notifyPerson(Person person, Role role, Type addressType, Identifier idToNotifyAbout, String activationKeyString) throws IllegalArgumentException, IllegalStateException { if (person == null) { throw new IllegalArgumentException("Person must be specified"); }/*from w w w . j ava2 s . c o m*/ if (idToNotifyAbout == null) { throw new IllegalArgumentException("Identifier must be specified"); } Name officialName = person.getOfficialName(); SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(findEmailAddressesForNotification(person, role, addressType)); msg.setFrom(messageSource.getMessage("activation.notify.from", null, null)); msg.setSubject(messageSource.getMessage("activation.notify.subject", null, null)); String greeting = (officialName == null) ? "" : officialName.getFormattedName(); msg.setText(messageSource.getMessage("activation.notify.body", new String[] { greeting, idToNotifyAbout.getValue(), activationKeyString }, null)); mailSender.send(msg); }
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));//from w w w .j a v a 2 s . c o 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;/* ww w . j a va 2s . co 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"; }