/**
   * Send a notification email if a planned match start has failed.<br>
   * <br>
   * The exact content will depend on the template defined in the mail.properties but support for
   * including {@link Match} properties is given by default. Normally the template should include
   * information about the role change like
   *
   * <ul>
   *   <li>the match name
   *   <li>the planned match start date
   * </ul>
   *
   * <br>
   * This method will do a generic lookup for all keys used in the template using {@link
   * MessageUtil#extractValues(List, Object...)}.
   *
   * @see MessageUtil#extractValues(List, Object...)
   * @see MessageUtil#getUsedTemplateKeys(String)
   * @see TemplateMailer#send(String, Map, String)
   * @param match - the match that could not been started
   * @param reason - the reason for the failure
   * @return true if a message has been send, false otherwise
   */
  public boolean sendMatchStartFailedNotification(Match match, String reason) {
    TemplateMailer m = get(match.getCreator());

    String template = TEMPLATE_MATCH_START_FAILED;
    List<String> keys = MessageUtil.getUsedTemplateKeys(m.getText(template));
    keys.addAll(MessageUtil.getUsedTemplateKeys(m.getSubject(template)));
    Map<String, Object> values = MessageUtil.extractValues(keys, match);
    values.put("reason", reason);
    // fill other values?
    try {
      return m.send(template, values, match.getCreator().getUser().getEmail());
    } catch (AddressException e) {
      logger.error("could not send mail to '" + e.getRef() + "'");
      return false;
    }
  }
  /*
   * (non-Javadoc)
   * @see com.syncnapsis.utils.mail.BaseApplicationMailer#checkMailer(java.lang.String,
   * com.syncnapsis.utils.mail.TemplateMailer)
   */
  @Override
  protected boolean checkMailer(String key, TemplateMailer mailer) {
    boolean valid = super.checkMailer(key, mailer);

    // check if all requried templates are present
    Set<String> templates = mailer.getTemplateNames();
    for (String req : REQUIRED_TEMPLATES) {
      if (!templates.contains(req)) {
        logger.error("required template '" + req + "' not found for mailer '" + key + "'");
        valid = false;
      }
    }
    return valid;
  }