private static IHealthChecksBuilder AddImapHealthCheck(this IHealthChecksBuilder builder, IConfiguration configuration) { var imapSettings = ConfigurationHandler.GetImapSettings(configuration); if (string.IsNullOrWhiteSpace(imapSettings.Host)) { logger.Info("IMAP Check: No valid Host found. Skipping check."); return(builder); } return(builder.AddImapHealthCheck(setup => { setup.Host = imapSettings.Host; setup.Port = imapSettings.Port.GetValueOrDefault(); setup.AllowInvalidRemoteCertificates = true; setup.ConnectionType = imapSettings.EnableSsl.Value == true ? ImapConnectionType.SSL_TLS : ImapConnectionType.AUTO; setup.LoginWith(imapSettings.Username, imapSettings.Password); })); }