Files

3.0 KiB

CMS-U5 — Contact mail + retry (summary)

Behaviour

  • A submission only stores the message (status new, mail pending, NextMailAttemptAt = now) and signals the background sender. The visitor never waits for SMTP.
  • ContactMailService (BackgroundService) wakes on the signal and every Contact:Mail:SweepSeconds; it picks unread (new) messages with mail pending/failed, fewer than MaxAttempts attempts and a due NextMailAttemptAt, oldest first, BatchSize at a time.
  • Claim: NextMailAttemptAt is a concurrency token; the sender first sets it to now + ClaimMinutes (whole seconds, the column is datetime), a second instance fails to save and skips the message.
  • Failure: failed + short error code, attempts + 1, next attempt after 5 min / 15 min / 1 h / 6 h / 24 h; after MaxAttempts (6) no automatic attempt; an administrator can still resend (ignores backoff and maximum).
  • Mail off or no valid recipient: nothing attempted or counted; the reason (disabled / recipient_not_configured) is shown as mailError.
  • Spam, read, archived messages are never auto-mailed. Module disabled: the service does nothing and never touches the database.
  • Mail: To = Contact:RecipientEmail, From = site sender, Reply-To = visitor (address validated, name only if valid), fixed subject "Nieuw bericht via {site}" / "New message via {site}"; details (name, e-mail, subject, message) HTML-encoded, line breaks kept, text part included. Logs: message id and short codes only.

Configuration (env-only for the address)

  • Contact__RecipientEmail (environment variable; no address in repo config).
  • Contact:Mail:SweepSeconds 120, MaxAttempts 6, BackoffMinutes [5,15,60,360,1440], ClaimMinutes 5, BatchSize 20.

API

  • Detail has nextMailAttemptAt; resend result has mailError. Migration ContactMailClaim (schema unchanged, concurrency token only). OpenAPI regenerated.

Shared files changed (additive only)

Core/Email/MailTypes.cs, MailTemplateRenderer.cs, SmtpEmailSender.cs (+66/-5). Existing Core tests untouched: 625 green.

Found by the real-database pipeline test

datetime drops fractions, which made the claim's concurrency check fail on the outcome save; claim time is now truncated to whole seconds.

Follow-up (review by AndreaSlopFotografie)

  • The "you can reply directly" note is removed from the ContactMessage catalog (Reply-To may be left out when the visitor address is invalid).
  • Plain text: every line of a visitor value is indented two spaces, so a visitor's own -- line or fake headings cannot imitate the layout.
  • NEW Core tests (next to the unchanged existing ones): ContactMessageMailRenderingTests (encoding of script/quotes/line breaks, labels encoded, null/empty Details give no block, fixed subject, text indent, no reply hint) and SmtpReplyToTests (valid Reply-To with name, invalid/CRLF address left out, control characters in the name dropped, none when absent), using the existing in-process stub SMTP server. Core: 639 green (625 existing + 14 new).