List of usage examples for org.springframework.mail SimpleMailMessage setFrom
@Override public void setFrom(String from)
From source file:ro.nextreports.server.web.security.recover.ForgotPasswordPage.java
public ForgotPasswordPage(PageParameters parameters) { super(parameters); add(new Image("logoImage", new LogoResource())); Form<Void> form = new Form<Void>("form"); // AdvancedForm<Void> form = new AdvancedForm<Void>("form"); add(form);//from w ww. j a va 2 s .co m // final NextFeedbackPanel feedbackPanel = new NextFeedbackPanel("feedback", form); final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback"); feedbackPanel.setOutputMarkupId(true); // form.add(feedbackPanel); form.add(feedbackPanel); TextField<String> usernameField = new RequiredTextField<String>("username", new PropertyModel<String>(this, "username")); usernameField.add(new DefaultFocusBehavior()); usernameField.setLabel(Model.of(getString("LoginPage.userName"))); form.add(usernameField); form.add(new AjaxSubmitLink("send") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { User user; try { user = securityService.getUserByName(username); } catch (NotFoundException e) { log.debug("Cannot find a user with name '{}'", username); setResponsePage(HomePage.class); return; } log.debug("Found user with name '{}'", username); String email = user.getEmail(); if (StringUtils.isEmpty(email)) { log.debug("User '{}' doesn't have an email address", username); setResponsePage(HomePage.class); return; } log.debug("Found email '{}'", email); // TODO verifica ca e setat un server de email pentru nextserver (in settings) Settings settings = storageService.getSettings(); String mailFrom = settings.getMailServer().getFrom(); String mailSubject = "NextReports Server: " + getString("ForgotPasswordPage.recover"); String resetToken = securityService.generateResetToken(user); // System.out.println("resetToken = " + resetToken); StringBuffer resetUrl = UrlUtil.getAppBaseUrl(storageService); resetUrl.append("reset?token=").append(resetToken); // System.out.println("resetUrl = " + resetUrl); String mailText = "NextReports Server\n\n" + getString("ForgotPasswordPage.recoverInfo") + "\n\n" + resetUrl; SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom(mailFrom); mailMessage.setTo(email); mailMessage.setSubject(mailSubject); mailMessage.setText(mailText); mailSender.send(mailMessage); log.debug("Sent password reset instuctions to '{}'", email); setResponsePage(HomePage.class); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { target.add(feedbackPanel); // target.add(form); } }); add(form); }
From source file:ubc.pavlab.aspiredb.server.controller.BaseController.java
/** * @param name/*ww w . jav a2s . c om*/ * @param subject * @param emailAddress * @param templateName * @param model */ protected void sendEmail(String name, String emailAddress, String subject, String templateName, Map<String, Object> model) { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom(ConfigUtils.getAdminEmailAddress()); mailMessage.setSubject(subject); mailMessage.setTo(name + "<" + emailAddress + ">"); mailEngine.sendMessage(mailMessage, templateName, model); }
From source file:ubc.pavlab.aspiredb.server.controller.SignupController.java
/** * Send an email to request signup confirmation. * /*w w w . j a v a 2 s . co m*/ * @param request * @param u */ private String sendResetConfirmationEmail(HttpServletRequest request, String token, String username, String password, String email) { String message = ""; // Send an account information e-mail SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom(ConfigUtils.getAdminEmailAddress()); mailMessage.setSubject(getText("signup.email.subject", request.getLocale())); try { Map<String, Object> model = new HashMap<>(); model.put("username", username); model.put("password", password); model.put("confirmLink", ConfigUtils.getBaseUrl() + "confirmRegistration.html?key=" + token + "&username=" + username); model.put("message", getText("login.passwordReset.emailMessage", request.getLocale())); String templateName = "passwordReset.vm"; sendEmail(username, email, getText("login.passwordReset.emailSubject", request.getLocale()), templateName, model); message = getText("login.passwordReset", new Object[] { username, email }, request.getLocale()); saveMessage(request, message); } catch (Exception e) { message = "Couldn't send password change confirmation email to " + email; throw new RuntimeException(message, e); } return message; }
From source file:ubc.pavlab.aspiredb.server.service.ProjectServiceImpl.java
private void sendEmail(String username, String email, Map<String, Object> model) { String subject = this.messageUtil.getText("projectUpload.email.subject", Locale.getDefault()); String templateName = "projectUploaded.vm"; SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom(ConfigUtils.getAdminEmailAddress()); mailMessage.setSubject(subject);//from w ww . j a v a 2s.c om mailMessage.setTo(username + "<" + email + ">"); mailEngine.sendMessage(mailMessage, templateName, model); }
From source file:ubc.pavlab.aspiredb.server.util.MailEngineImpl.java
/** * Sends a message to the gemma administrator as defined in the Gemma.properties file * /* w w w. j a va2 s.co m*/ * @param bodyText * @param subject */ @Override public void sendAdminMessage(String bodyText, String subject) { if ((bodyText == null) && (subject == null)) { log.warn("Not sending empty email, both subject and body are null"); return; } log.info("Sending email notification to administrator regarding: " + subject); SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(ConfigUtils.getAdminEmailAddress()); msg.setFrom(ConfigUtils.getAdminEmailAddress()); msg.setSubject(subject); msg.setText(bodyText); this.send(msg); }
From source file:ubic.gemma.core.util.MailUtilsImpl.java
@Override public void sendTaskCompletedNotificationEmail(EmailNotificationContext emailNotificationContext, TaskResult taskResult) {/*from w ww . j av a 2 s .c om*/ String taskId = emailNotificationContext.getTaskId(); String submitter = emailNotificationContext.getSubmitter(); String taskName = emailNotificationContext.getTaskName(); if (StringUtils.isNotBlank(submitter)) { User user = userService.findByUserName(submitter); assert user != null; String emailAddress = user.getEmail(); if (emailAddress != null) { MailUtilsImpl.log.info("Sending email notification to " + emailAddress); SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(emailAddress); msg.setFrom(Settings.getAdminEmailAddress()); msg.setSubject("Gemma task completed"); String logs = ""; if (taskResult.getException() != null) { logs += "Task failed with :\n"; logs += taskResult.getException().getMessage(); } msg.setText("A job you started on Gemma is completed (taskId=" + taskId + ", " + taskName + ")\n\n" + logs + "\n"); mailEngine.send(msg); } } }
From source file:ubic.gemma.persistence.util.MailEngineImpl.java
/** * Sends a message to the gemma administrator as defined in the Gemma.properties file *///from www .j a v a2 s . c o m @Override public void sendAdminMessage(String bodyText, String subject) { if ((bodyText == null) && (subject == null)) { MailEngineImpl.log.warn("Not sending empty email, both subject and body are null"); return; } MailEngineImpl.log.info("Sending email notification to administrator regarding: " + subject); SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(Settings.getAdminEmailAddress()); msg.setFrom(Settings.getAdminEmailAddress()); msg.setSubject(subject); msg.setText(bodyText); this.send(msg); }
From source file:ubic.gemma.util.MailUtilsImpl.java
@Override public void sendTaskCompletedNotificationEmail(EmailNotificationContext emailNotificationContext, TaskResult taskResult) {/*from www .java 2s . com*/ String taskId = emailNotificationContext.getTaskId(); String submitter = emailNotificationContext.getSubmitter(); String taskName = emailNotificationContext.getTaskName(); if (StringUtils.isNotBlank(submitter)) { User user = userService.findByUserName(submitter); assert user != null; String emailAddress = user.getEmail(); if (emailAddress != null) { log.debug("Sending email notification to " + emailAddress); SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(emailAddress); msg.setFrom(ConfigUtils.getAdminEmailAddress()); msg.setSubject("Gemma task completed"); String logs = ""; if (taskResult.getException() != null) { logs += "Task failed with :\n"; logs += taskResult.getException().getMessage(); } msg.setText("A job you started on Gemma is completed (taskid=" + taskId + ", " + taskName + ")\n\n" + logs + "\n"); /* * TODO provide a link to something relevant something like: */ // String url = ConfigUtils.getBaseUrl() + "user/tasks.html?taskId=" + taskId; mailEngine.send(msg); } } }
From source file:ubic.gemma.web.controller.BaseController.java
protected void sendConfirmationEmail(HttpServletRequest request, String token, String username, String email, Map<String, Object> model, String templateName) { try {/* w w w.j a v a2 s . c om*/ model.put("username", username); model.put("confirmLink", Settings.getBaseUrl() + "confirmRegistration.html?key=" + token + "&username=" + username); SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setFrom(Settings.getAdminEmailAddress()); mailMessage.setSubject(getText("signup.email.subject", request.getLocale())); mailMessage.setTo(username + "<" + email + ">"); mailEngine.sendMessage(mailMessage, templateName, model); } catch (Exception e) { log.error("Couldn't send email to " + email, e); } }
From source file:ubic.gemma.web.controller.common.auditAndSecurity.SecurityControllerImpl.java
@Override public boolean addUserToGroup(String userName, String groupName) { User userTakingAction = userManager.getCurrentUser(); if (userTakingAction == null) { throw new IllegalStateException("Cannot add user to group when user is not logged in"); }//from w ww .ja va 2s .c o m User u; if (userManager.userExists(userName)) { u = userManager.findByUserName(userName); if (!u.getEnabled()) { throw new IllegalArgumentException("Sorry, that user's account is not enabled."); } securityService.addUserToGroup(userName, groupName); } else if (userManager.userWithEmailExists(userName)) { u = userManager.findByEmail(userName); if (!u.getEnabled()) { throw new IllegalArgumentException("Sorry, that user's account is not enabled."); } String uname = u.getUserName(); securityService.addUserToGroup(uname, groupName); } else { throw new IllegalArgumentException("Sorry, there is no matching user."); } /* * send the user an email. */ String emailAddress = u.getEmail(); if (StringUtils.isNotBlank(emailAddress)) { SecurityControllerImpl.log.debug("Sending email notification to " + emailAddress); SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(emailAddress); msg.setFrom(Settings.getAdminEmailAddress()); msg.setSubject("You have been added to a group on Gemma"); msg.setText(userTakingAction.getUserName() + " has added you to the group '" + groupName + "'.\nTo view groups you belong to, visit " + SecurityControllerImpl.GROUP_MANAGER_URL + "\n\nIf you believe you received this email in error, contact " + Settings.getAdminEmailAddress() + "."); mailEngine.send(msg); } return true; }