Example #1
0
  private void sendEmail(Task.Status exitStatus, File logFile)
      throws IOException, MessagingException, TemplateException {
    String smtpServer = RepoxContextUtil.getRepoxManager().getConfiguration().getSmtpServer();
    if (smtpServer == null || smtpServer.isEmpty()) {
      return;
    }

    String fromEmail = RepoxContextUtil.getRepoxManager().getConfiguration().getDefaultEmail();
    String recipientsEmail =
        RepoxContextUtil.getRepoxManager().getConfiguration().getAdministratorEmail();
    String adminMailPass = RepoxContextUtil.getRepoxManager().getConfiguration().getMailPassword();
    String subject = "REPOX Data Source ingesting finished. Exit status: " + exitStatus.toString();

    EmailSender emailSender = new EmailSender();
    String pathIngestFile =
        URLDecoder.decode(
            Thread.currentThread().getContextClassLoader().getResource("ingest.html.ftl").getFile(),
            "ISO-8859-1");
    emailSender.setTemplate(
        pathIngestFile.substring(0, pathIngestFile.lastIndexOf("/")) + "/ingest");

    HashMap map = new HashMap<String, String>();
    map.put("exitStatus", exitStatus.toString());
    map.put("id", id);

    JavaMailSenderImpl mail = new JavaMailSenderImpl();
    // mail.setUsername(fromEmail);
    mail.setUsername(recipientsEmail);

    mail.setPassword(adminMailPass);

    mail.setPort(25);

    Properties props = System.getProperties();

    props.put("mail.smtp.host", smtpServer);
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    mail.setJavaMailProperties(props);

    emailSender.setMailSender(mail);
    emailSender.sendEmail(recipientsEmail, fromEmail, subject, map, logFile.getAbsolutePath());
  }