Repository navigation
feat(email): an SMTP adapter, and the native server sends the reset mail when it has a relay - #176
Merged
Merged
Conversation
SmtpEmail, on lettre (rustls on ring, the Mozilla roots, no native-tls, no pool), for the self-hosted set. It reads THRUST_SMTP_* through SmtpConfig::from_lookup: a host, a sender, a TLS mode (starttls, which is required and never falls back to the clear, tls, or none), a port by the mode, a login (both or neither, refused with none: the password would go in the clear), a CA file that is then the only trust, and a deadline for the whole message. A half-written configuration is an error that names the variable and never carries a password, and Debug redacts it. A 5xx from the relay and a message lettre cannot make are Rejected; a 4xx, an unreachable or silent relay and a failed handshake are Unavailable. The recipient must be one bare address, so a list, a name or a line break and a header after it is refused before a connection is made. The id the port returns is the Message-ID it wrote. Tests: smtp_wire (hermetic, a scripted server in the test's own process: all 600 reply codes by first digit, a relay that cannot do TLS not used when TLS is asked for, a generated property that what arrives is what was given as read by mailparse, and every address core accepts is one it can send to), smtp_config (hermetic, 54,000 combinations against a reference) and smtp_sink (Docker: Mailpit, with STARTTLS, implicit TLS and a login, each beside its controls). Six planted bugs, one per defect, each fails the suite aimed at it. deny.toml allows 0BSD (quoted_printable, under lettre; mailparse, a dev-dependency, is 0BSD too). check-deps.sh names lettre among what core must not depend on and what the Worker graph must not contain. Refs: #46 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
thrust-server builds the SMTP adapter from THRUST_SMTP_* and hands it to the app, and logs one line saying which relay it will use (and that the reset stays off if THRUST_PUBLIC_BASE_URL is not set). With a relay and a base URL, is_smtp_configured is true and the reset mails a link; without them nothing changes. The Worker still has no mail service (its send_email binding is E3), so a deployed Worker is dark. A new contract pass, mail (native targets, a cell in contract-all.sh): the real server beside a Mailpit container, and tests/mail.rs walks request, message, link and reset against a mail server that parses the message for itself, with a forged Host that must not change the link and a second request inside the cooldown that must mail nothing. scripts/contract.sh now asks /api/instances/ before every pass: true for mail, false for all the others, which also unset THRUST_SMTP_* and THRUST_PUBLIC_BASE_URL first, so a developer's shell cannot turn the dark test into a test of something else. scripts/mutants.sh: nine new rows (the adapter's six, thrust-server's mutant_smtp_unwired, and two core mutants run against the mail pass, one of which, the cooldown, could until now only be killed by core's own tests). smtp-flag-always-on, which the new guard refuses before a test runs, is a refusal row now. The CI Docker job runs smtp_sink, and nextest keeps it out of the hermetic loop as it does pg_adapter. Records: G-38, the runbook in infra.md (every THRUST_SMTP_* variable), the port row in app.md, F-A03 and Q-0073.1, the pass and its cell in running.md, contract-suite.md and cicd.md, and the mutants in mutation.md. Refs: #46 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
A mutants row that was neither killed nor refused said only "SURVIVED or did not run (exit=4)", and on a runner the row's own output is thrown away with the job, so the one thing a red job needed, the reason, was missing: contract.sh says why it stopped (a server that exited early, one that never became healthy, a mail server that did not come up, a build that failed) in that output. On PR #176 the job failed twice, on different rows each time (two rows of the new mail pass with exit 3 and 4 in the first attempt, an old row with exit 4 in the second), and nothing in the log could tell a startup flake from a fault of the new rows. A row that is not killed now prints the end of its own output to the job log, and a killed row prints nothing. Refs: #46 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
G-38 recorded that the edited scripts/mutants.sh had not run to the end. It has now: green in CI on ab6045f. The record also says what the road to that was: two attempts of the CI run on the updated branch failed in the mutants job on rows that never started (exit 3 and 4 of the two new mail rows in the first, exit 4 of an old row in the second, a different row each time), the startup failure this job has shown before, whose cause is not established; the script now prints the end of a row's own output when a row is not killed. Refs: #46 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The second half of the mail path for the password reset (E2): an SMTP adapter for the
EmailSenderport that #169 added, built from the environment bythrust-server.With this PR the native server can send the reset mail, when it is given a relay (
THRUST_SMTP_*) and aTHRUST_PUBLIC_BASE_URL. Without them nothing changes: a deployment answersSMTP_NOT_CONFIGURED, saysis_smtp_configured: false, and the app keeps drawing the "ask your admin" line. The Worker is still dark (itssend_emailbinding is E3), so no deployment you run today starts sending mail when this merges.Refs #46 (it does not close it).
The plan, and where this PR sits
EmailSenderport, the token table, the two routes,is_smtp_configuredfrom configurationSmtpEmailonlettre, wired intothrust-server, proved against a scripted server and against Mailpitsend_emailbinding, wired inwrangler.deploy.toml, and a real send on staging: needs your sender domain and your explicit go-ahead before anything is sentWhat it does
Configuration, read once when the server starts (
crates/thrust-adapters-selfhosted/src/smtp.rs, anddocs/src/architecture/infra.mdfor the runbook):THRUST_SMTP_HOSTTHRUST_SMTP_*without it stops the server at startTHRUST_SMTP_FROMTHRUST_SMTP_TLSstarttls(default; required, a relay that cannot upgrade is not used in the clear),tls(port 465), ornoneTHRUST_SMTP_PORTTHRUST_SMTP_USERNAME,THRUST_SMTP_PASSWORDtls=noneTHRUST_SMTP_CA_FILETHRUST_SMTP_TIMEOUT_SECSDebugredacts it too).Rejected; a 4xx, a relay that cannot be reached or does not answer in time, and a failed handshake areUnavailable. Either is the pin's generic 500 and leaves no link behind (shown by hand on the real server: both requests tried to send, neither was held back by a link that was never delivered).Message-IDthe adapter wrote.mail: SMTP relay <host>:<port>, tls=<mode>, from <address>, ...), and says so if there is no base URL, because then the reset stays off.Things you may want to look at
deny.tomlgains0BSD.lettrebringsquoted_printable(0BSD), andmailparse, a dev-dependency, is 0BSD too. It is permissive with no attribution clause; the licence list is a policy file, so I am saying it here and not burying it.lettre(rustls onring, asreqwestalready is, Mozilla roots; nonative-tls, no pool, no hostname lookup) and its four small ones (email-encoding,email_address,nom8,quoted_printable).scripts/check-deps.shnow nameslettreamong the crates core must not depend on and the Worker graph must not contain (it is absent from both).THRUST_SMTP_CA_FILEtrusts only that CA when set. I chose "only", as the Postgres adapter'sverify-cadoes, over "added to the Mozilla roots": a self-hosted relay with a private CA should not also be trusted for whatever a public CA signs. The cost is that a deployment that wants both cannot have both. Say if you want it the other way.native-memory mail(and a Docker step in thepg-adapterjob forsmtp_sink). The cell is generated fromscripts/contract-all.sh; it pullsaxllent/mailpit:v1.33.1from Docker Hub aspostgres:16-alpineis pulled. The required-contexts set is unchanged (a new cell is not a required context).Tests and controls
tests/smtp_wire(hermetic, in the default loop; a scripted SMTP server in the test's own process, 9 tests): every reply code the grammar has at every step of the conversation (600 cases) read by its first digit; a relay that is silent, hangs up or is not there; a relay that cannot do TLS not used when TLS is asked for; a generated property that what arrives is what was given, read bymailparseand not bylettre(one sender, one recipient, text, subject, the returned id, and no header nobody meant, with line breaks andBcc:in the subject); every address core'sis_valid_emailaccepts is one the adapter sends to; a recipient that is not one bare address refused with nothing sent.tests/smtp_config(hermetic, 4 tests): all 54,000 combinations of the eight settings against an independently written reference; the password in no error and noDebug; a bad CA file.tests/smtp_sink(Docker, 7 tests, Mailpit): the message as a server that is not ours reads it; Mailpit's own 4xx and 5xx; STARTTLS, implicit TLS and a login, each with controls (the server requires TLS, so a plain client is refused by the server; another CA, a certificate that does not name the host, and the Mozilla roots alone are refused; no login and a wrong password are refused).mailpass (native-memory mailandnative-pg mail, 3 tests): the real server beside a Mailpit; request, message, link, and the reset; a forgedHostdoes not change the link; a second request inside the cooldown mails nothing. The pass refuses to run unless/api/instances/says mail is on, every other pass refuses to run unless it says off and unsetsTHRUST_SMTP_*first, so a developer's shell cannot turn the dark test into a test of something else.scripts/mutants.shrows, and one old row converted: see Measured): the adapter's six (a refusal read as an outage and the reverse; the sender taken from the recipient; a wrong id returned; a password allowed in the clear; any certificate trusted; STARTTLS made opportunistic),thrust-server'smutant_smtp_unwired(the relay read and not handed to the app: themailpass refuses to run, exit 5), and two core mutants run against themailpass, one of which (mutant_reset_ignores_cooldown) could until now only be killed by the core's own tests.lettresays so); a run of spaces in a subject sent as encoded words comes back as none (RFC 2047 6.2, cosmetic);lettrewrites a BEL into a header as it is (not an injection; the only text a person controls is the address, which is checked); Mailpit's published ports took connections a moment after its log said it was ready (the helper waits for the220and the API).Measured
scripts/contract.sh <target> main:native-memory,native-pg,worker-memory,worker-cfEXPECT_MAINunchanged), with the new guard that holdsis_smtp_configuredatfalsescripts/contract.sh native-memory mail,native-pg mailcargo nextest run --profile ci --workspacesmtp_wire, 4 insmtp_config)cargo test -p thrust-adapters-selfhosted --test smtp_sink(Docker, Mailpit)cargo test --doc --workspace,cargo fmt --all --check, clippy (native, every target; the Worker's wasm32),cargo deny --locked checkdepsandci-scriptsjobs, all 30 steps (the dependency graph, topology and its self-test, Plane 500 and its self-test, the acceptance list and its self-test, placement, the render and workflow lints, the web diff, the 19 helper-script tests)ci-scriptsanddenywere run again on the finished treescripts/mutants.shas a whole, once, on the tree before its last editsmtp-flag-always-on, a server that says mail is on though nothing can send it, which the new main-pass guard now refuses (exit 5) before a test runs, so the row's "exit 101" test failed. The defect is still caught (by the guard, bytests/reset.rsand by the recorded S01), so I made it a refusal row and ran that row by hand: refused. The script as edited ran to the end in CI (below)mutants.shrowsmail-pass rows killed, and themail-pass guard refused: in that whole runThe six contract cells ran before the last two edits (a cfg-gated mutant in the adapter, and a formatting change in a test); neither changes what a build without the mutant does, and
smtp_wire,smtp_sinkand the workspace were run again after them.CI
Green on
ab6045f(run 43678220241, first attempt of that run): 34 jobs successful,mutants(12 minutes) and thenative-memory mailcell among them. The two runs before it are described under Not measured.Not measured
infra.md, not removed).mdbook build.mutants, and a new run after the commit below is green: the first attempt had two rows of the newmailpass that never started (exit 3 and exit 4), the second had one old row that never started (reset-token-reusable, exit 4), a different row each time, and the job's log said nothing more because a row's own output is thrown away. That is the "server never came up" failure this job has shown before on rows unrelated to a PR; I have not established its cause, and cannot say whether the nine rows added here (three of them start a Docker container) make it likelier. The last commit makes the job print the end of a row's output when it is not killed, so the next one explains itself.Files
crates/thrust-adapters-selfhosted(src/smtp.rs;tests/smtp_wire,smtp_config,smtp_sink; six mutant features),crates/thrust-server(composition root, one mutant),crates/thrust-contract-tests/tests/mail.rs,scripts/contract.sh(themailpass, the guard, the unsets),contract-all.sh,mutants.sh,check-deps.sh,verify-all.sh,.github/workflows/ci.ymlandcontract-cell.yml,.config/nextest.toml,deny.toml, and the docs:infra.md(the runbook),app.md,cicd.md,status.md(G-38),running.md,contract-suite.md,mutation.md,TRACEABILITY.md,QUESTIONS.md.🤖 Generated with Claude Code