List of usage examples for org.springframework.mail SimpleMailMessage SimpleMailMessage
public SimpleMailMessage(SimpleMailMessage original)
From source file:pmp.springmail.TestDrive.java
void sendEmailViaSpring(String text) { SimpleMailMessage message = new SimpleMailMessage(template); message.setTo("oldlamer@mail333.com"); // message.setFrom("pmpozitron@gmail.com"); message.setText(text);/*ww w .ja va 2 s.c o m*/ sender.send(message); }
From source file:org.cgiar.dapa.ccafs.tpe.service.impl.TPEMailService.java
@Override public void sendPreConfiguredMail(String message) { log.info("Sending the default mail..."); SimpleMailMessage mailMessage = new SimpleMailMessage(defaultMail); mailMessage.setText(message);//from w w w.j ava2s. co m mailSender.send(mailMessage); log.info("Sent..."); }
From source file:com.admob.rocksteady.reactor.Email.java
/** * Handle the triggered event/*w w w. j av a2 s . c o m*/ * * @param newEvents the new events in the window * @param oldEvents the old events in the window */ public void update(EventBean[] newEvents, EventBean[] oldEvents) { if (newEvents == null) { return; } for (EventBean newEvent : newEvents) { try { String name = newEvent.get("name").toString(); String value = newEvent.get("value").toString(); String colo = newEvent.get("colo").toString(); SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(this.recipient); logger.info(" event triggered - type " + type + " - " + colo + " - " + name + " - " + value); msg.setText(" event triggered - type " + type + " - " + colo + " - " + name + " - " + value); // this.mailSender.send(msg); } catch (Exception e) { logger.error("Problem with event: " + newEvent.toString()); } } }
From source file:edu.txstate.dmlab.clusteringwiki.web.RegisterController.java
@RequestMapping("register.*") public String getRegisterPage(HttpServletRequest request, HttpServletResponse response, Model model) { String action = request.getParameter("applAction"); if (action != null && action.equals("register") && isAjaxRequest(request)) { //requesting registration String email = request.getParameter("email"); String password = request.getParameter("password"); String firstName = request.getParameter("firstname"); String lastName = request.getParameter("lastname"); if (email == null || password == null) { sendOutput(response, "{\"error\":\"Invalid registration request received.\"}"); return null; }/* w ww . j a v a 2s . c o m*/ email = email.toLowerCase(); IUserDao dao = applicationUser.getUserDao(); User user = dao.selectUserByEmail(email); if (user != null) { sendOutput(response, "{\"error\":\"An account is already registered with this " + "email. Please use the forgot password feature to retrieve your credentials " + "or choose an alternate email address.\"}"); return null; } //Create a thread safe "sandbox" of the mailMessage SimpleMailMessage msg = new SimpleMailMessage(mailMessage); msg.setSubject("ClusteringWiki account created"); msg.setTo(email); msg.setText("Dear " + firstName + ", \n\n" + "A ClusteringWiki account has been created for this email address. Log in to ClusteringWiki to " + "start editing search result clusters. Right-click on nodes to access available " + "editing operations. Your edits will improve search for you as well as others " + "quering similar things. \n\n " + "\n\nThank you,\n\nClusteringWiki Admin"); try { mailSender.send(msg); } catch (MailException ex) { if (ex.contains(com.sun.mail.smtp.SMTPAddressFailedException.class)) { sendOutput(response, "{\"error\":\"Invalid email address. Please specify a valid email address.\"}"); } else if (!ex.contains(com.sun.mail.smtp.SMTPSendFailedException.class)) { //ignore not being able to send this message out. sendOutput(response, "{\"error\":\"Email message could not be sent: <br><br>" + StringEscapeUtils.escapeJavaScript(ex.getMessage().replace("\n", "<br>")) + "\"}"); } return null; } user = new User(); user.setEmail(email); user.setPassword(password); user.setFirstName(firstName); user.setLastName(lastName); try { dao.saveUser(user); } catch (Exception e) { sendOutput(response, "{\"error\":\"Registration failed: " + e.getMessage() + ".\"}"); return null; } applicationUser.setEmail(email); applicationUser.setPassword(password); try { applicationUser.logIn(); } catch (Exception e) { sendOutput(response, "{\"error\":\"Login error: " + e.getMessage() + "\"}"); return null; } sendOutput(response, "{\"success\":true}"); return null; } return "register"; }
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; }//from w w w .j ava 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:com.gnizr.web.action.user.ApproveUserAccount.java
private boolean sendNotificationEmail(User user) { Map<String, Object> model = new HashMap<String, Object>(); model.put("token", token); model.put("username", user.getUsername()); model.put("email", user.getEmail()); model.put("createdOn", user.getCreatedOn()); model.put("gnizrConfiguration", getGnizrConfiguration()); if (getWelcomeEmailTemplate() == null) { logger.error("ApproveUserAccount: welcomeEmailTemplate bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; }//from w w w.j a va2s . co m String toUserEmail = user.getEmail(); if (toUserEmail == null) { logger.error("ApproveUserAccount: the email of user " + user.getUsername() + " is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_EMAIL_UNDEF)); return false; } SimpleMailMessage notifyMsg = new SimpleMailMessage(getWelcomeEmailTemplate()); notifyMsg.setTo(toUserEmail); if (notifyMsg.getFrom() == null) { String contactEmail = getGnizrConfiguration().getSiteContactEmail(); if (contactEmail != null) { notifyMsg.setFrom(contactEmail); } else { notifyMsg.setFrom("no-reply@localhost"); } } Template fmTemplate1 = null; String text1 = null; try { fmTemplate1 = freemarkerEngine.getTemplate("login/welcome-template.ftl"); text1 = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate1, model); } catch (Exception e) { logger.error("ApproveUserAccount: error creating message template from Freemarker engine"); } notifyMsg.setText(text1); if (getMailSender() == null) { logger.error("ApproveUserAccount: mailSender bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; } try { getMailSender().send(notifyMsg); return true; } catch (Exception e) { logger.error("ApproveUserAccount: send mail error. " + e); addActionError(String.valueOf(ActionErrorCode.ERROR_INTERNAL)); } return false; }
From source file:org.runway.users.service.UserManagerServiceImpl.java
private void sendMail(User user) { SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage); msg.setTo(user.getEmail());/* w w w.j av a 2 s . c o 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:com.gnizr.web.action.user.RegisterUser.java
private boolean sendNotifyAndApproval(String token, User user) { Map<String, Object> model = new HashMap<String, Object>(); model.put("token", token); model.put("username", user.getUsername()); model.put("email", user.getEmail()); model.put("createdOn", user.getCreatedOn()); model.put("gnizrConfiguration", getGnizrConfiguration()); if (getNotifyEmailTemplate() == null) { logger.error("RegisterUser: notifyEmailTemplate bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; }//from ww w .j a va 2s.c om if (getApprovalEmailTemplate() == null) { logger.error("RegisterUser: approvalEmailTemplate bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; } String toUserEmail = user.getEmail(); String toAppvEmail = getGnizrConfiguration().getSiteContactEmail(); if (toUserEmail == null) { logger.error("RegisterUser: the email of user " + user.getUsername() + " is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_EMAIL_UNDEF)); return false; } SimpleMailMessage notifyMsg = new SimpleMailMessage(getNotifyEmailTemplate()); notifyMsg.setTo(toUserEmail); if (notifyMsg.getFrom() == null) { String contactEmail = getGnizrConfiguration().getSiteContactEmail(); if (contactEmail != null) { notifyMsg.setFrom(contactEmail); } else { notifyMsg.setFrom("no-reply@localhost"); } } SimpleMailMessage approvalMsg = new SimpleMailMessage(getApprovalEmailTemplate()); if (toAppvEmail != null) { approvalMsg.setTo(toAppvEmail); approvalMsg.setFrom(toUserEmail); } else { logger.error("RegisterUser: siteContactEmail is not defined. Can't sent approval emaili. Abort."); return false; } Template fmTemplate1 = null; Template fmTemplate2 = null; String text1 = null; String text2 = null; try { fmTemplate1 = freemarkerEngine.getTemplate("login/notifyemail-template.ftl"); fmTemplate2 = freemarkerEngine.getTemplate("login/approvalemail-template.ftl"); text1 = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate1, model); text2 = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate2, model); } catch (Exception e) { logger.error("RegisterUser: error creating message template from Freemarker engine"); } notifyMsg.setText(text1); approvalMsg.setText(text2); if (getMailSender() == null) { logger.error("RegisterUser: mailSender bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; } try { getMailSender().send(notifyMsg); getMailSender().send(approvalMsg); return true; } catch (Exception e) { logger.error("RegisterUser: send mail error. " + e); addActionError(String.valueOf(ActionErrorCode.ERROR_INTERNAL)); } return false; }
From source file:com.admob.rocksteady.reactor.Alerting.java
/** * Handle the triggered event//from ww w. j a v a2 s.c om * * @param newEvents the new events in the window * @param oldEvents the old events in the window */ public void update(EventBean[] newEvents, EventBean[] oldEvents) { if (newEvents == null) { return; } Integer i = 0; Date sqlDate = new Date(); for (EventBean newEvent : newEvents) { i++; try { String msg = ""; String _subject = ""; // This is how string comparison is done in JAVA, not == if (type.equals("log")) { String name = newEvent.get("name").toString(); // String value = newEvent.get("value").toString(); String error = newEvent.get("error").toString(); String count = newEvent.get("count").toString(); msg = name + " - " + error + " - " + count + " errors."; } else if (type.equals("latency_single")) { String hostname = newEvent.get("hostname").toString(); String name = newEvent.get("name").toString(); String value = newEvent.get("value").toString(); String colo = newEvent.get("colo").toString(); String app = newEvent.get("app").toString(); String graphiteTs = newEvent.get("timestamp").toString(); msg = colo + " - " + hostname + " - " + app + " - " + name + " - " + value; Threshold threshold = new Threshold(); threshold.setName(name); threshold.setHostname(hostname); threshold.setColo(colo); threshold.setApp(app); threshold.setGraphiteTs(graphiteTs); threshold.setGraphiteValue(value); threshold.setCreateOn(sqlDate); threshold.persist(); msg = msg + "\n" + "http://" + rsweb + "/rsweb/threshold.php?id=" + String.valueOf(threshold.getId()); _subject = this.subject + " - " + colo + " - " + hostname; } else if (type.equals("latency_multi")) { Metric l = (Metric) newEvent.get("latency"); String l_hostname = l.getHostname(); String l_value = l.getValue().toString(); String l_name = l.getName(); Metric w = (Metric) newEvent.get("win"); String name = w.getName(); String value = w.getValue().toString(); String ts = w.getTimestamp().toString(); String colo = w.getColo(); String hostname = w.getHostname(); String app = w.getApp(); msg = l_hostname + " - " + l_name + " - " + l_value + " - " + app + " - " + name + " - " + value + " - " + ts; // Persistent the threshold cross event Threshold threshold = new Threshold(); threshold.setName(name); threshold.setHostname(hostname); threshold.setColo(colo); threshold.setApp(app); threshold.setGraphiteTs(ts); threshold.setGraphiteValue(value); threshold.setCreateOn(sqlDate); threshold.persist(); } else if (type.equals("deploy")) { String new_revision = newEvent.get("revision").toString(); String colo = newEvent.get("colo").toString(); String hostname = newEvent.get("hostname").toString(); String app = newEvent.get("app").toString(); Revision revision = new Revision(); revision.setHostname(hostname); revision.setColo(colo); revision.setApp(app); revision.setCreateOn(sqlDate); revision.setRevision(new_revision); revision.persist(); msg = "Revision changed on " + colo + " " + hostname + " to " + new_revision; } else if (type.equals("test")) { // String hostname = newEvent.get("hostname").toString(); String colo = newEvent.get("colo").toString(); // String app = newEvent.get("app").toString(); // String timestamp = newEvent.get("timestamp").toString(); // String revision = newEvent.get("revision").toString(); // String diff = newEvent.get("diff").toString(); String value = newEvent.get("value").toString(); String name = newEvent.get("name").toString(); msg = colo + " - " + name + " - " + value; } else if (type.equals("averagedThreshold")) { DecimalFormat df = new DecimalFormat("#.##"); String colo = newEvent.get("colo").toString(); String app = newEvent.get("app").toString(); String value = df.format(newEvent.get("value")); String name = newEvent.get("name").toString(); msg = app + " - " + colo + " - " + name + " - " + value; _subject = this.subject + " - " + msg; } else if (type.equals("count")) { String count = newEvent.get("count").toString(); msg = i + " count: " + count; } else { String name = newEvent.get("name").toString(); String value = newEvent.get("value").toString(); String colo = newEvent.get("colo").toString(); msg = " event triggered - type " + type + " - " + colo + " - " + name + " - " + value; } logger.debug(msg); // This email recipient iisn't empty, we send email out. if (recipients != null & recipients.length > 0) { logger.debug("Email sent"); SimpleMailMessage mail = new SimpleMailMessage(this.templateMessage); mail.setTo(this.recipients); mail.setSubject(_subject); mail.setText(msg); this.mailSender.send(mail); } } catch (Exception e) { logger.error("Trouble. Alert type: " + type + " " + newEvent.toString() + " - " + e.getMessage()); } } }
From source file:edu.txstate.dmlab.clusteringwiki.web.LoginController.java
@RequestMapping("reminder.*") public void sendReminder(HttpServletRequest request, HttpServletResponse response, Model model) { // send an email with link to allow changing password String action = request.getParameter("applAction"); if (action != null && action.equals("sendReminder") && isAjaxRequest(request)) { //requesting registration String email = request.getParameter("email"); if (email == null) { sendOutput(response, "{\"error\":\"Invalid reminder request received.\"}"); return; }/*from www. j a va 2 s . co m*/ email = email.toLowerCase(); IUserDao dao = applicationUser.getUserDao(); User user = dao.selectUserByEmail(email); if (user == null) { sendOutput(response, "{\"error\":\"Invalid email. Please try again.\"}"); return; } //create password request link CredentialsRequest cred = new CredentialsRequest(); cred.setEmail(email); String link = request.getRequestURL().toString(); link = link.replace("reminder.html", "changePassword.html?key=" + cred.getKey()); //Create a thread safe "sandbox" of the mailMessage SimpleMailMessage msg = new SimpleMailMessage(mailMessage); msg.setTo(email); msg.setText("Dear " + user.getFirstName() + ", \n\n" + "We have received a forgot password request at ClusteringWiki for the account " + "associated with this email address. If you did not initiate this request, please " + "ignore this email message. Otherwise, copy and paste the link below in your " + "browser to complete your password reset. Please note this forgot pasword request " + "will expire in one hour. \n\n " + link + "\n\nThank you,\n\nClusterWiki Admin"); try { mailSender.send(msg); } catch (MailException ex) { if (ex.contains(com.sun.mail.smtp.SMTPAddressFailedException.class)) { sendOutput(response, "{\"error\":\"The email address is no longer valid. Please contact an administrator or create a new account.\"}"); } else if (ex.contains(com.sun.mail.smtp.SMTPSendFailedException.class)) { //ignore not being able to send this message out. sendOutput(response, "{\"error\":\"Email message could not be sent. Please try again later.\"}"); } else sendOutput(response, "{\"error\":\"Email message could not be sent: <br><br>" + StringEscapeUtils.escapeJavaScript(ex.getMessage().replace("\n", "<br>")) + "\"}"); return; } //make valid and save credentials request cred.setValid(1); try { credentialsRequestDao.saveCredentialsRequest(cred); } catch (Exception e) { sendOutput(response, "{\"error\":\"Credential request could not be saved. Please try again.\"}"); return; } sendOutput(response, "{\"success\":true}"); return; } }