List of usage examples for org.springframework.mail SimpleMailMessage setTo
@Override public void setTo(String... to)
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()])); }// w w w .ja v a2 s . com } 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:csns.web.controller.SubmissionController.java
private void emailGrade(Submission submission) { if (!StringUtils.hasText(submission.getGrade()) || submission.isGradeMailed()) return;/* w ww .jav a2s . c om*/ User instructor = SecurityUtils.getUser(); User student = submission.getStudent(); SimpleMailMessage message = new SimpleMailMessage(); message.setFrom(instructor.getEmail()); message.setTo(student.getEmail()); String subject = submission.getAssignment().getSection().getCourse().getCode() + " " + submission.getAssignment().getName() + " Grade"; message.setSubject(subject); Map<String, Object> vModels = new HashMap<String, Object>(); vModels.put("grade", submission.getGrade()); String comments = submission.getComments(); vModels.put("comments", comments != null ? comments : ""); String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "email.submission.grade.vm", appEncoding, vModels); message.setText(text); try { mailSender.send(message); submission.setGradeMailed(true); submissionDao.saveSubmission(submission); logger.info(instructor.getUsername() + " sent grade to " + student.getEmail()); } catch (MailException e) { logger.warn(instructor.getUsername() + " failed to send grade to " + student.getEmail()); logger.debug(e.getMessage()); } }
From source file:com.appleframework.monitor.service.EmailService.java
public void _notify(Alert alert) { Project project = projectService.findProject(alert.getProjectName()); if (project == null) { logger.error("projectName of alert is null, alert={}", alert); return;/*from w w w . j av a2 s . c o m*/ } SimpleMailMessage sm = new SimpleMailMessage(); sm.setText(alert.getContent()); sm.setSubject(alert.getTitle()); sm.setFrom(from); String mailList = alert.getMetricDog().getMailList(); if (StringUtils.isBlank(mailList)) mailList = project.getMailList(); if (StringUtils.isNotBlank(mailList)) sm.setTo(mailList.split(",")); else logger.error("send mail fail ,because mail list is null"); send(sm); }
From source file:in.mycp.controller.LoginController.java
public void sendMessage(String mailFrom, String subject, String mailTo, String message) { org.springframework.mail.SimpleMailMessage mailMessage = new org.springframework.mail.SimpleMailMessage(); mailMessage.setFrom(mailFrom);//from w ww .j a v a2 s . c o m mailMessage.setSubject(subject); mailMessage.setTo(mailTo); mailMessage.setText(message); mailTemplate.send(mailMessage); }
From source file:com.logsniffer.event.publisher.MailPublisher.java
@Override public void publish(final Event event) throws PublishException { try {/*ww w. ja v a 2s . c om*/ final VelocityContext context = velocityRenderer.getContext(event); final SimpleMailMessage email = new SimpleMailMessage(); email.setFrom(getFrom()); email.setSubject(velocityRenderer.render(getSubject(), context)); email.setText(velocityRenderer.render(getTextMessage(), context) + " "); final String to2 = getTo(); email.setTo(to2.split(",|\\s")); mailSender.send(email); logger.info("Sent event notification to: {}", to2); } catch (final MailException e) { throw new PublishException("Failed to send event notification to mail: " + getTo(), e); } }
From source file:org.jasig.schedassist.impl.events.EmailNotificationApplicationListener.java
/** * /* w ww. j av a2 s. c o m*/ * @param owner * @param visitor * @param event */ protected void sendEmail(final IScheduleOwner owner, final IScheduleVisitor visitor, final VEvent event, final String messageBody) { if (null != mailSender) { SimpleMailMessage message = new SimpleMailMessage(); if (!isEmailAddressValid(owner.getCalendarAccount().getEmailAddress())) { message.setFrom(noReplyFromAddress); message.setTo(new String[] { visitor.getCalendarAccount().getEmailAddress() }); } else { message.setFrom(owner.getCalendarAccount().getEmailAddress()); message.setTo(new String[] { owner.getCalendarAccount().getEmailAddress(), visitor.getCalendarAccount().getEmailAddress() }); } Summary summary = event.getSummary(); if (summary != null) { message.setSubject(summary.getValue()); } else { LOG.warn("event missing summary" + event); message.setSubject("Appointment"); } message.setText(messageBody); LOG.debug("sending message: " + message.toString()); mailSender.send(message); LOG.debug("message successfully sent"); } else { LOG.debug("no mailSender set, ignoring sendEmail call"); } }
From source file:com.gnizr.web.action.user.RegisterUser.java
private boolean sendEmailVerification(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 (getVerifyEmailTemplate() == null) { logger.error("RegisterUser: templateMessge bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; }/*from www. j av a2 s. co m*/ String toEmail = user.getEmail(); if (toEmail == null) { logger.error("RegisterUser: the email of user " + user.getUsername() + " is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_EMAIL_UNDEF)); return false; } SimpleMailMessage msg = new SimpleMailMessage(getVerifyEmailTemplate()); 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/verifyemail-template.ftl"); text = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate, model); } catch (Exception e) { logger.error("RegisterUser: error creating message template from Freemarker engine"); } msg.setText(text); if (getMailSender() == null) { logger.error("RegisterUser: mailSender bean is not defined"); addActionError(String.valueOf(ActionErrorCode.ERROR_CONFIG)); return false; } try { getMailSender().send(msg); return true; } catch (Exception e) { logger.error("RegisterUser: send mail error. " + e); addActionError(String.valueOf(ActionErrorCode.ERROR_INTERNAL)); } return false; }
From source file:org.jasig.schedassist.impl.events.AutomaticAttendeeRemovalApplicationListener.java
@Async @Override/* www. jav a 2s . c o m*/ 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: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 . jav a 2 s . co m 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:uk.ac.ebi.intact.editor.batch.admin.MailNotifierStepExecutionListener.java
public ExitStatus afterStep(StepExecution stepExecution) { SimpleMailMessage message = newSimpleMessage(); message.setSubject("[Editor_import] Finished step: " + stepExecution.getStepName() + " Exit status: " + stepExecution.getExitStatus().getExitCode()); message.setText(stepExecution.toString() + "\n" + stepExecution.getExecutionContext()); message.setText(stepExecution.toString() + "\n" + stepExecution.getSummary() + "\n" + stepExecution.getJobExecution()); message.setTo(stepExecution.getJobParameters().getString("email.recipient")); try {//ww w . jav a2 s .c o m mailSender.send(message); } catch (MailException e) { log.error("Impossible to send e-mail", e); } return stepExecution.getExitStatus(); }