/**
   * @param act
   * @param locale
   * @param exception
   */
  private void sendKrashAuditEmail(Act act, Locale locale, Exception exception) {
    ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale);
    String emailFrom = bundle.getString(RECIPIENT_KEY);
    String projectName = getProjectNameFromAct(act);

    if (isAllowedToSendKrashReport && CollectionUtils.isNotEmpty(krashReportMailList)) {
      Set<String> emailToSet = new HashSet<>();
      emailToSet.addAll(krashReportMailList);
      String host = "";
      try {
        host = InetAddress.getLocalHost().getHostName();
      } catch (UnknownHostException uhe) {
      }

      String msgSubject = bundle.getString(KRASH_ADMIN_SUBJECT_KEY);
      msgSubject = StringUtils.replace(msgSubject, PROJECT_NAME_TO_REPLACE, projectName);
      msgSubject = StringUtils.replace(msgSubject, HOST_TO_REPLACE, host);

      String msgContent = bundle.getString(KRASH_ADMIN_MSG_CONTENT_KEY);
      msgContent = StringUtils.replace(msgContent, PROJECT_NAME_TO_REPLACE, projectName);
      msgContent =
          StringUtils.replace(
              msgContent, USER_EMAIL_TO_REPLACE, act.getContract().getUser().getEmail1());
      msgContent = StringUtils.replace(msgContent, HOST_TO_REPLACE, host);
      msgContent =
          StringUtils.replace(
              msgContent, EXCEPTION_TO_REPLACE, ExceptionUtils.getStackTrace(exception));
      if (act.getAudit().getSubject() != null) {
        msgContent =
            StringUtils.replace(
                msgContent, AUDIT_URL_TO_REPLACE, act.getAudit().getSubject().getURL());
      }
      LOGGER.info(
          "krash email sent to " + krashReportMailList + " on audit n° " + act.getAudit().getId());
      sendEmail(emailFrom, emailToSet, msgSubject, msgContent);
    }

    String emailTo = act.getContract().getUser().getEmail1();
    if (this.emailSentToUserExclusionList.contains(emailTo)) {
      LOGGER.info("Email not set cause user " + emailTo + " belongs to " + "exlusion list");
      return;
    }
    Set<String> emailToSet = new HashSet<>();
    emailToSet.add(emailTo);
    String msgSubject = bundle.getString(KRASH_SUBJECT_KEY);
    msgSubject = StringUtils.replace(msgSubject, PROJECT_NAME_TO_REPLACE, projectName);
    String msgContent = bundle.getString(KRASH_MSG_CONTENT_KEY);
    msgContent = StringUtils.replace(msgContent, PROJECT_NAME_TO_REPLACE, projectName);
    msgContent =
        StringUtils.replace(
            msgContent, PROJECT_URL_TO_REPLACE, buildContractUrl(act.getContract()));
    LOGGER.info("krash email sent to [" + emailTo + "]" + " on audit n° " + act.getAudit().getId());
    sendEmail(emailFrom, emailToSet, msgSubject, msgContent);
  }
 /**
  * @param act
  * @return
  */
 private String buildResultUrl(Act act) {
   StringBuilder strb = new StringBuilder();
   strb.append(webappUrl);
   strb.append(pageResultUrlSuffix);
   strb.append(act.getAudit().getId());
   return strb.toString();
 }
 /**
  * @param act
  * @return
  */
 private String getProjectNameFromAct(Act act) {
   StringBuilder projectName = new StringBuilder();
   projectName.append(act.getContract().getLabel());
   if (act.getScope().getCode().equals(ScopeEnum.SCENARIO)) {
     projectName.append(" - ");
     // the name of the scenario is persisted on engine's side as the URL
     // of the parent WebResource
     projectName.append(act.getAudit().getSubject().getURL());
   }
   return projectName.toString();
 }
  /**
   * @param act
   * @param bundle
   * @param emailFrom
   * @param emailTo
   * @param projectName
   */
  private void sendSuccessfulMessageOnActTerminated(
      Act act, ResourceBundle bundle, String emailFrom, Set<String> emailTo, String projectName) {

    String emailSubject =
        bundle.getString(SUCCESS_SUBJECT_KEY).replaceAll(PROJECT_NAME_TO_REPLACE, projectName);

    String messageContent = bundle.getString(SUCCESS_MSG_CONTENT_KEY);
    messageContent = messageContent.replaceAll(URL_TO_REPLACE, buildResultUrl(act));
    messageContent = messageContent.replaceAll(PROJECT_NAME_TO_REPLACE, projectName);

    LOGGER.info("success email sent to " + emailTo + " on audit n° " + act.getAudit().getId());
    sendEmail(emailFrom, emailTo, emailSubject, messageContent);
  }
 /**
  * @param act
  * @param bundle
  * @return
  */
 private void sendFailureMessageOnActTerminated(
     Act act, ResourceBundle bundle, String emailFrom, Set<String> emailTo, String projectName) {
   String emailSubject =
       bundle.getString(ERROR_SUBJECT_KEY).replaceAll(PROJECT_NAME_TO_REPLACE, projectName);
   String messageContent;
   if (act.getScope().getCode().equals(ScopeEnum.DOMAIN)) {
     messageContent = bundle.getString(SITE_ERROR_MSG_CONTENT_KEY);
   } else {
     messageContent = bundle.getString(PAGE_ERROR_MSG_CONTENT_KEY);
   }
   messageContent =
       messageContent.replaceAll(PROJECT_URL_TO_REPLACE, buildContractUrl(act.getContract()));
   messageContent = messageContent.replaceAll(URL_TO_REPLACE, buildResultUrl(act));
   messageContent = messageContent.replaceAll(PROJECT_NAME_TO_REPLACE, projectName);
   LOGGER.info("failure email sent to " + emailTo + " on audit n° " + act.getAudit().getId());
   sendEmail(emailFrom, emailTo, emailSubject, messageContent);
 }