Skip to content

feat(portal): email order confirmations and withdrawal receipts - #615

Merged
devantler merged 2 commits into
mainfrom
claude/portal-email
Nov 15, 2026
Merged

devantler merged 2 commits into
mainfrom
claude/portal-email

Conversation

@devantler

@devantler devantler commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Two Danish-law items blocked switching the portal on. The portal must itself email an order confirmation (Consumer Contracts Act, section 13) and a withdrawal receipt (section 20 a) on a durable medium. Until now the operator did this by hand. This PR sends both through the site's existing send-only SES sender (devantler-tech/platform#5400): no new sender.

  • internal/mail. A small SMTP submission client for that sender.
    • It refuses a server that offers no STARTTLS before it sends any credential, and verifies the server's certificate.
    • It authenticates with PLAIN only after TLS, and sends from no-reply@devantler.tech only.
    • Messages are UTF-8 plain text, quoted-printable. Subjects are encoded and headers checked for injection.
    • Its errors never carry an address, subject or body.
  • Queued with what causes them. Placing an order queues its confirmation, and confirming a withdrawal queues its receipt, in the same transaction (portal_mail_outbox, migration v23). Each is queued once per order and kind, in the client's language, to the client's contact address. A retry or a repeated withdrawal queues nothing more. A client without a contact address gets nothing, and the operator's page says so.
    • The confirmation restates the order:
      • its scope and deliverables, prices and terms, and the payment path;
      • the early-start request, in the agreed wording, or the first day work may begin;
      • the last day to withdraw, and how (the portal or ned@devantler.tech);
      • a link to the terms with the model withdrawal form.
    • The receipt says the agreement has ended, and what happens to what was paid, with or without an early start.
  • Sent by one replica. RunMail sends the queue every minute under an advisory lock, the same one-replica pattern as the invoice sync, now a shared withRunLock. It sends nothing while the portal's identity gate is closed, and it checks the gate again before each email, so closing the portal stops delivery. It records each delivery once (portal_mail_deliveries). A failure stops the pass and is tried again on the next one; a message whose delivery record was lost may arrive twice.
  • Operator page. It shows each email as queued or sent. The withdrawal note now says the portal emails the receipt, instead of asking the operator to.
  • Configuration. The sender starts only when PORTAL_SMTP_USERNAME_FILE and PORTAL_SMTP_PASSWORD_FILE name the projected credential, both or neither. PORTAL_SMTP_ADDR (port 587 only; default the SES endpoint) and PORTAL_MAIL_FROM (default no-reply@devantler.tech) are optional, and all four are accepted from the settings projection. Without them nothing is sent, and orders and withdrawals only exist behind the false-default billing gates.
  • Storage. v23 grants SELECT/INSERT only on both tables, and the start-up role check covers them. The fixture reset now clears 31 tables.

Rollout

  1. feat(business-site): give the portal the site's SES sender for its emails platform#6368 adds smtp-username and smtp-password to business-site-runtime, and SES egress on 587.
  2. Once it has deployed, a small package PR mounts the two items and documents the settings lines. It must not ship before #6368, because a missing mounted key keeps new pods from starting.
  3. Turning the portal on adds the settings lines.

SES is in its sandbox until AWS grants production access, so for now it delivers only to verified addresses.

Tests run locally (PostgreSQL 17, Go 1.27.4)

  • TestSendRequiresTLSAndAuthentication runs against a fake SMTP server with real STARTTLS:
    • the envelope and the headers;
    • the decoded UTF-8 subject;
    • the exact quoted-printable body.
  • TestSendRefusesWithoutTLSOrWithAWrongCredential:
    • a server without STARTTLS never receives the credential;
    • a wrong credential and an untrusted certificate fail cleanly;
    • named or injected addresses and an empty body are refused;
    • invalid configuration is refused.
  • TestOrderAndWithdrawalAreConfirmedByEmail:
    • a Danish early-start order queues its confirmation with the agreed content and the accepted deliverables;
    • a refused send records nothing;
    • with the identity gate closed nothing is sent, and reopening it resumes;
    • two passes send it once;
    • a withdrawal sends its English receipt once, even when repeated;
    • the operator page shows both as sent.
  • TestOrderWithoutContactQueuesNoEmail and TestMailConfigIsOptionalAndStrict (plus the settings projection) cover the remaining paths.
  • The full Go suite passes: all four cohorts, contactintegration and contacttrialintegration.
  • golangci-lint, vet, gofmt and deadcode are clean. HTMLHint, spelling and jscpd are clean too (MegaLinter's 5.4.2 configuration).

Builds on #613, now merged. Part of #21

🤖 Generated with Claude Code

The portal must itself confirm an order on a durable medium (Consumer
Contracts Act, section 13) and acknowledge a withdrawal (section 20 a);
until now the operator did this by hand. It now uses the site's
existing send-only SES sender (platform#5400).

- internal/mail is a small SMTP submission client: STARTTLS before any
  credential, a verified certificate, PLAIN after TLS, a fixed sender,
  UTF-8 plain text, and errors that carry no address or content.
- Placing an order queues its confirmation, and a withdrawal its
  receipt, in the same transaction (portal_mail_outbox, migration v23),
  once per order and kind, in the client's language, to their contact
  address. The confirmation restates the order, the early-start request
  or the first day work may begin, the last day to withdraw and the
  terms.
- One replica sends the queue every minute under an advisory lock,
  shared with the invoice sync, and records each delivery once. The
  operator's page shows each email as queued or sent.
- The sender starts only when the projected credential files are
  configured. Orders and withdrawals stay behind the billing gates.

Part of #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@devantler

Copy link
Copy Markdown
Contributor Author

🤖 Generated by the Agentic Engineer

@codex review for Portal email: the SMTP client's STARTTLS-before-AUTH and certificate checks, header injection, queuing in the order and withdrawal transactions, the one-replica send loop and delivery records, migration v23 and its role check, and that no address or body reaches logs or errors

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T21:47:46.005491Z fc2a15b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 98309075db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/internal/identity/portal_mail.go Resolved
Comment thread server/internal/identity/order.go Resolved
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

✅MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Max errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 1.56s
✅ CSS stylelint 1 0 0 0 2.75s
✅ GO golangci-lint yes yes no no 165.04s
✅ GO revive 179 0 0 1.14s
✅ HTML djlint 5 0 0 2.45s
✅ HTML htmlhint 5 0 0 0.39s
✅ JSON jsonlint 2 0 0 0.11s
✅ JSON prettier 2 0 0 0 0.85s
✅ JSON v8r 2 0 0 1.07s
✅ MARKDOWN markdownlint 17 0 0 0 2.51s
✅ MARKDOWN markdown-table-formatter 17 0 0 0 0.57s
✅ REPOSITORY betterleaks yes no no 1.09s
✅ REPOSITORY checkov yes no no 23.84s
✅ REPOSITORY git_diff yes no no 0.24s
✅ REPOSITORY grype yes no no 248.35s
✅ REPOSITORY osv-scanner yes no no 204.13s
✅ REPOSITORY secretlint yes no no 1.58s
✅ REPOSITORY syft yes no no 3.53s
✅ REPOSITORY trivy yes no no 13.73s
✅ REPOSITORY trivy-sbom yes no no 0.52s
✅ REPOSITORY trufflehog yes no no 6.6s
✅ SPELL cspell 206 0 0 8.85s
✅ SPELL lychee 24 0 0 176.13s

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@10.2.0 --custom-flavor-setup --custom-flavor-linters COPYPASTE_JSCPD,CSS_STYLELINT,GO_GOLANGCI_LINT,GO_REVIVE,HTML_DJLINT,HTML_HTMLHINT,JSON_JSONLINT,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_BETTERLEAKS,REPOSITORY_GRYPE,REPOSITORY_OSV_SCANNER,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,SPELL_CSPELL,SPELL_LYCHEE

MegaLinter is provided by OX Security
Show us your support by starring ⭐ the repository

@github-code-quality

github-code-quality Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Go

Go / code-coverage/go

main claude/portal-email fc2a15b +/-
— 78% —

Line coverage data for the main branch is not yet available.

View coverage of the 10 most covered files.
File main claude/portal-email fc2a15b +/-
internal/identity/browser.go — 90% —
internal/webapp/app.go — 89% —
internal/identity/contact.go — 89% —
internal/custom...ity/material.go — 85% —
internal/identity/request.go — 82% —
internal/runtimeapp/config.go — 80% —
internal/identi...ork_approval.go — 79% —
internal/identi...l_acceptance.go — 77% —
internal/identity/card.go — 77% —
internal/identity/billing.go — 69% —

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 15, 2026 21:51 UTC

Codex review on #615:
- The send loop now sends nothing while the portal's identity gate is
  closed, and checks the gate again before each email, so closing the
  portal stops delivery.
- The order confirmation now also restates the accepted deliverables,
  in both languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@devantler

Copy link
Copy Markdown
Contributor Author

🤖 Generated by the Agentic Engineer

@codex review for Re-review: the mail loop stops while the identity gate is closed, and the order confirmation includes the accepted deliverables

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: fc2a15b818

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@devantler
devantler marked this pull request as ready for review November 15, 2026 21:58
@devantler
devantler requested a review from a team as a code owner November 15, 2026 21:58
@devantler
devantler merged commit 94d7516 into main Nov 15, 2026
40 of 53 checks passed
@devantler
devantler deleted the claude/portal-email branch November 15, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant