public static void FromConnectionString(this SmtpHealthCheckOptions setup, string cs) { var c = new SmtpConnectionBuilder(cs); setup.Host = c.Server; setup.Port = c.Port; setup.ConnectionType = c.UseSsl ? SmtpConnectionType.TLS : SmtpConnectionType.PLAIN; if (c.Username != null) { setup.LoginWith(c.Username, c.Password); } }
/// <summary> /// Add a health check for network SMTP connection. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="setup">The action to configure SMTP connection parameters.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'smtp' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns></param> public static IHealthChecksBuilder AddSmtpHealthCheck(this IHealthChecksBuilder builder, Action <SmtpHealthCheckOptions> setup, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default) { var options = new SmtpHealthCheckOptions(); setup?.Invoke(options); return(builder.Add(new HealthCheckRegistration( name ?? SMTP_NAME, sp => new SmtpHealthCheck(options), failureStatus, tags))); }
private static SmtpHealthCheckOptions Options(EmailServerSettings settings) { var option = new SmtpHealthCheckOptions { Host = settings.Host, Port = settings.Port, ConnectionType = SmtpConnectionType.AUTO, }; option.LoginWith(settings.UserName, settings.Password); return(option); }