@Override
 public Result check() {
   try {
     javaMailSender
         .getSession()
         .getTransport()
         .connect(
             javaMailSender.getHost(), javaMailSender.getUsername(), javaMailSender.getPassword());
     return Result.healthy();
   } catch (Exception e) {
     log.debug("Cannot connect to e-mail server: {}", e);
     return Result.unhealthy("Cannot connect to e-mail server");
   }
 }
 private void organMailContent() {
   mailSender.setHost(ConfigManager.getInstance().getString("mail.host"));
   mailSender.setPort(ConfigManager.getInstance().getInt("mail.port", 25));
   mailSender.setUsername(ConfigManager.getInstance().getString("mail.username"));
   mailSender.setPassword(ConfigManager.getInstance().getString("mail.password"));
   mailSender.setDefaultEncoding("utf-8");
   log.info(
       "HOST>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>mailSender.getHost()="
           + mailSender.getHost()
           + ",mailSender.getPort()="
           + mailSender.getPort());
   Properties props = new Properties();
   props.setProperty("mail.smtp.auth", "true");
   props.setProperty("mail.smtp.timeout", "0");
   mailSender.setJavaMailProperties(props);
   this.setMailSender(mailSender);
 }
  @Override
  protected void doHealthCheck(Health.Builder builder) throws Exception {
    log.debug("Initializing JavaMail health indicator");
    try {
      javaMailSender
          .getSession()
          .getTransport()
          .connect(
              javaMailSender.getHost(),
              javaMailSender.getPort(),
              javaMailSender.getUsername(),
              javaMailSender.getPassword());

      builder.up();

    } catch (MessagingException e) {
      log.debug("Cannot connect to e-mail server. Error: {}", e.getMessage());
      builder.down(e);
    }
  }