E-mailfeature Operations: deployment, monitoring, productiegereedheid; configuratiefouten als Error-log
Mislukte mails door een configuratieprobleem (auth_failed, rejected_sender, tls_failed, not_configured) worden als Error gelogd zodat Sentry een alert stuurt; timeouts en ontvangerproblemen blijven Warning. Documentatie: uitrol per host met de hand in shared/env, rollback, monitoringplan, checklist; ASF-productie op IIS als open punt voor een latere feature. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,10 @@ public sealed class SmtpEmailSender(IOptions<EmailOptions> options, ILogger<Smtp
|
||||
public async Task<MailSendResult> SendAsync(OutgoingMail mail, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_options.Smtp.Host))
|
||||
{
|
||||
logger.LogError("identity_mail_failed code={Code} reason=no_smtp_host", MailSendResult.NotConfigured);
|
||||
return MailSendResult.Fail(MailSendResult.NotConfigured);
|
||||
}
|
||||
|
||||
var fromAddress = mail.FromAddress ?? _options.FromAddress;
|
||||
var fromName = mail.FromName ?? _options.FromName;
|
||||
@@ -89,7 +92,8 @@ public sealed class SmtpEmailSender(IOptions<EmailOptions> options, ILogger<Smtp
|
||||
// Never the whole exception text (it can quote addresses or credentials): the type, for a refused
|
||||
// command its phase and status code, a redacted, shortened first line of the server's reply, and the
|
||||
// time each phase took.
|
||||
logger.LogWarning(
|
||||
logger.Log(
|
||||
SmtpFailure.LevelFor(code),
|
||||
"identity_mail_failed code={Code} detail={Detail} phase={Phase} timings=\"{Timings}\" timeout_per_phase_s={TimeoutSeconds} from_domain={FromDomain} smtp_port={Port}",
|
||||
code, SmtpFailure.Describe(ex), phase, string.Join(" ", phases), _options.Smtp.TimeoutSeconds, DomainOf(fromAddress), _options.Smtp.Port);
|
||||
return MailSendResult.Fail(code);
|
||||
|
||||
@@ -47,6 +47,21 @@ public static partial class SmtpFailure
|
||||
_ => MailSendResult.Unknown
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// True for failures that point at the host's mail CONFIGURATION (wrong credentials, a sender the account may not
|
||||
/// use, a TLS problem, mail not configured) and need a person to fix them. Timeouts, a refused recipient and
|
||||
/// unknown errors are not: they pass by themselves or are about one message.
|
||||
/// </summary>
|
||||
public static bool IsConfigurationProblem(string? code) =>
|
||||
code is MailSendResult.AuthFailed or MailSendResult.RejectedSender or MailSendResult.TlsFailed or MailSendResult.NotConfigured;
|
||||
|
||||
/// <summary>
|
||||
/// Log level of a failed mail: Error for a configuration problem (Sentry turns Error events into an alert to the
|
||||
/// project owner), Warning for the rest (journal and breadcrumbs only).
|
||||
/// </summary>
|
||||
public static Microsoft.Extensions.Logging.LogLevel LevelFor(string? code) =>
|
||||
IsConfigurationProblem(code) ? Microsoft.Extensions.Logging.LogLevel.Error : Microsoft.Extensions.Logging.LogLevel.Warning;
|
||||
|
||||
/// <summary>"timeout_connect", "timeout_auth" or "timeout_send" when the phase is known, else plain "timeout".</summary>
|
||||
public static string TimeoutCode(string? phase) => phase switch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user