private void sendResults(
      HashMap<String, List<String>> results,
      String reportEmail,
      String subject,
      String logPath,
      String fileName) {
    StringBuilder message = new StringBuilder(1024);
    message.ensureCapacity(256);

    List<String> messages = ((List<String>) results.get("errors"));
    if ((messages != null) && (0 < messages.size())) {
      message.append("\nError Found:\n\n");
      Logger.info(ContentImporterThread.class, "\nError Found:\n");

      for (String tempMsg : messages) {
        message.append(tempMsg + "\n");
        Logger.info(ContentImporterThread.class, tempMsg);
      }
    }

    messages = ((List<String>) results.get("warnings"));
    if ((messages != null) && (0 < messages.size())) {
      message.append("\nWarnings Found:\n\n");
      Logger.info(ContentImporterThread.class, "\nWarnings Found:\n");

      for (String tempMsg : messages) {
        message.append(tempMsg + "\n");
        Logger.info(ContentImporterThread.class, tempMsg);
      }
    }

    messages = ((List<String>) results.get("results"));
    if ((messages != null) && (0 < messages.size())) {
      message.append("\nResults:\n\n");
      Logger.info(ContentImporterThread.class, "\nResults:\n");

      for (String tempMsg : messages) {
        message.append(tempMsg + "\n");
        Logger.info(ContentImporterThread.class, tempMsg);
      }
    }

    Company company = PublicCompanyFactory.getDefaultCompany();

    contentImporterLogger(logPath, fileName, message.toString());
    if (UtilMethods.isSet(reportEmail)) {
      Mailer m = new Mailer();
      m.setToEmail(reportEmail);
      m.setFromEmail(company.getEmailAddress());
      m.setCc(null);
      m.setBcc(null);
      m.setSubject(subject);
      m.setTextBody(message.toString());

      if (!m.sendMessage()) {
        Logger.info(ContentImporterThread.class, "Email couldn't be sent.");
      }
    }
  }
示例#2
0
 public void setHTMLAndTextBody(String HTMLBody) {
   try {
     MimeBodyPart bp = new MimeBodyPart();
     String contentEncoding = "text/html;charset=" + encoding;
     bp.setContent(HTMLBody, contentEncoding);
     bp.setHeader("Content-Transfer-Encoding", "base64");
     sendingText.addBodyPart(bp);
     bp = new MimeBodyPart();
     String x = HTMLBody.replaceAll("<[^>]*>", " ");
     while (x.indexOf("  ") > -1) {
       x = x.replaceAll("  ", " ");
     }
     setTextBody(x);
   } catch (Exception f) {
     Logger.error(this, "failed to setHTMLAndTextBody:" + f, f);
   }
 }