2.2 KiB
2.2 KiB
CMS-U5 — Contact mail + retry (summary)
Behaviour
- A submission only stores the message (status
new, mailpending,NextMailAttemptAt = now) and signals the background sender. The visitor never waits for SMTP. ContactMailService(BackgroundService) wakes on the signal and everyContact:Mail:SweepSeconds; it picks unread (new) messages with mailpending/failed, fewer thanMaxAttemptsattempts and a dueNextMailAttemptAt, oldest first,BatchSizeat a time.- Claim:
NextMailAttemptAtis a concurrency token; the sender first sets it to now +ClaimMinutes(whole seconds, the column isdatetime), 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; afterMaxAttempts(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 asmailError. - 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:SweepSeconds120,MaxAttempts6,BackoffMinutes[5,15,60,360,1440],ClaimMinutes5,BatchSize20.
API
- Detail has
nextMailAttemptAt; resend result hasmailError. MigrationContactMailClaim(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.