List of usage examples for org.springframework.mail SimpleMailMessage setText
@Override public void setText(String text)
From source file:org.runway.users.service.UserManagerServiceImpl.java
private void sendMail(User user) { SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(user.getEmail());//from www . ja v a 2 s .co m msg.setSubject("Re: your peoplebees account "); StringBuilder sb = new StringBuilder(); // sb.append("Dear "+ user.getFirstName() + "\n"); sb.append("your peoplebees account is created successfully.\n "); // the following format is correct. please don't change sb.append(" login id: " + user.getId() + "\n"); sb.append("http://peoplebees.com\n"); msg.setText(sb.toString()); logger.info("sending message : \n" + msg.toString()); this.mailSender.sendMail(msg); }
From source file:edu.wisc.jmeter.MonitorListener.java
/** * Executes a shell script to send an email. *///w w w . j ava2 s . com private void sendEmail(Date now, String subject, String body, String host, Status status) { log("Sending email (" + status + "): " + subject + " - " + body); final SimpleMailMessage message = new SimpleMailMessage(); message.setTo(emailTo); message.setFrom(emailFrom); message.setSubject(subject); message.setText(body); try { this.javaMailSender.send(message); } catch (MailException me) { log("Failed to send email", me); } }
From source file:ca.uoguelph.ccs.portal.services.feedback.dao.SimpleFeedbackMessageFormatterImpl.java
public SimpleMailMessage format(Feedback feedback) { SimpleMailMessage message = new SimpleMailMessage(); message.setTo(targetEmail);/* ww w .j av a 2 s.co m*/ message.setFrom(fromAddress); message.setSubject("[Feedback] " + feedback.getSubject()); StringBuffer details = new StringBuffer(); details.append("NAME: "); details.append(null == feedback.getName() ? "<empty>" : feedback.getName()); details.append("\n"); details.append("\n"); details.append("EMAIL: "); details.append(null == feedback.getEmailAddress() ? "<empty>" : feedback.getEmailAddress()); details.append("\n"); details.append("\n"); details.append("DETAILS: "); details.append(feedback.getDetails()); message.setText(details.toString()); return message; }
From source file:org.jasig.schedassist.impl.events.AutomaticAttendeeRemovalApplicationListener.java
@Async @Override//from ww w .j a v a2 s . c om public void onApplicationEvent(AutomaticAttendeeRemovalEvent event) { ICalendarAccount owner = event.getOwner(); VEvent vevent = event.getEvent(); Property removedAttendee = event.getRemoved(); String removedAttendeeEmail = removedAttendee.getValue() .substring(EmailNotificationApplicationListener.MAILTO_PREFIX.length()); deleteEventReminder(owner, vevent, removedAttendeeEmail); SimpleMailMessage message = new SimpleMailMessage(); if (!EmailNotificationApplicationListener.isEmailAddressValid(owner.getEmailAddress())) { message.setFrom(noReplyFromAddress); } else { message.setFrom(owner.getEmailAddress()); } message.setTo(removedAttendeeEmail); Summary summary = vevent.getSummary(); if (summary != null) { message.setSubject(summary.getValue() + " has been updated"); } else { LOG.warn("event is missing summary: " + event); message.setSubject("Appointment has been updated"); } message.setText(constructMessageBody(vevent, removedAttendee, owner.getDisplayName())); LOG.debug("sending message: " + message.toString()); mailSender.send(message); LOG.debug("message successfully sent"); }
From source file:csns.web.controller.SectionGradeController.java
private void emailGrade(Enrollment enrollment) { if (enrollment.getGrade() == null || enrollment.isGradeMailed()) return;//from w ww .ja 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:com.edgenius.wiki.gwt.server.HelperControllerImpl.java
public boolean sendNotify(String receiver, String text) { SimpleMailMessage msg = new SimpleMailMessage(); msg.setSubject(messageService.getMessage("sent.msg.title")); if (receiver == null) { if (!StringUtils.isBlank(Global.DefaultReceiverMail)) msg.setTo(Global.DefaultReceiverMail); if (Global.ccToSystemAdmin || StringUtils.isBlank(Global.DefaultReceiverMail)) { Set<String> bcc = userReadingService.getSystemAdminMailList(); if (bcc != null && bcc.size() > 0) msg.setBcc(bcc.toArray(new String[bcc.size()])); }/*from w w w .j a v a2 s .c om*/ } else { //TODO: send message to special user - receiver is userID or email address? } msg.setFrom(Global.DefaultNotifyMail); msg.setText(text + "\r\n" + messageService.getMessage("sent.by") + " " + WikiUtil.getUser().getFullname()); mailService.send(msg); return true; }
From source file:net.triptech.metahive.service.OpenIdAuthenticationFailureHandler.java
/** * Send a notification email.//from w w w . ja v a2 s . com * * @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; }//w w w .j av a2s .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:fi.koku.pyh.controller.EditFamilyInformationController.java
/** * Action method for adding new family members. * /*from w w w . 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:hu.unideb.studentSupportInterface.backing.Registration.java
public void addUser() { if (userDao.loadUserByUsername(newUser.getEmail()) != null) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Ez az e-mail cm mr szerepel az adatbzisban.", "Ez az e-mail cm mr szerepel az adatbzisban...")); return;// w ww. j a v a 2 s. c o m } if (!newUser.getPassword().equals(pwdCheck)) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "A kt jelsz nem egyezik.", "A kt jelsz nem egyezik.")); return; } if (!selectedRoles.contains(Role.TUTOR)) { newUser.setActive(true); } newUser = userDao.createUser(newUser, newUser.getPassword()); for (Role r : selectedRoles) { roleDao.addRoleToUser(newUser, r); } for (Language l : selectedLanguages) { languageDao.addLanguageToUser(l, newUser); } SimpleMailMessage msg = new SimpleMailMessage(); msg.setFrom("SSI"); msg.setTo(newUser.getEmail()); String text; if (selectedRoles.contains(Role.TUTOR)) { text = "Kedves " + newUser.getFirstName() + "!\r\n\r\nSikeresen regisztrltl a Student Support Interface alkalmazsba!\r\nMivel oktatknt regisztrltl, felhasznli fikod csak adminisztrtori jvhagys utn lesz hasznlhat. Errl egy jabb zenetben fogsz rteslni.\r\n\r\ndvzlettel:\r\nStudent Support Interface"; } else { text = "Kedves " + newUser.getFirstName() + "!\r\n\r\nSikeresen regisztrltl a Student Support Interface alkalmazsba!\r\n\r\ndvzlettel:\r\nStudent Support Interface"; } msg.setSubject("Sikeres regisztrci"); msg.setText(text); mailSender.send(msg); FacesContext facesContext = FacesContext.getCurrentInstance(); String outcome = "existingSolutions?faces-redirect=true";// Do your thing? facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, outcome); }