Skip to content

feat(aspire): catch Identity email locally with MailPit - #1739

Merged
BenjaminMichaelis merged 2 commits into
mainfrom
claude/mailpit-identity-emails
Nov 28, 2026
Merged

BenjaminMichaelis merged 2 commits into
mainfrom
claude/mailpit-identity-emails

Conversation

@BenjaminMichaelis

Copy link
Copy Markdown
Member

Summary

Local Identity email (registration confirmation, password reset, email change) previously went nowhere in Development. No IEmailSender was registered, so Identity's no-op sender dropped every message, and RequireConfirmedEmail meant local accounts couldn't be confirmed without editing the database. This PR catches that email in a local MailPit container and tests the flows end to end.

  • AppHost: adds MailPit (CommunityToolkit.Aspire.Hosting.MailPit 17.0.0) and references it from Web. The data volume and persistent lifetime apply only when EphemeralDatabases is false, the same as SQL Server and Postgres.
  • Web: adds SmtpEmailSender, built on MailKit following its documented connect → send → disconnect pattern, with plaintext and no auth because that's what MailPit accepts.
    • It's used only in Development, and only when ConnectionStrings:mailpit is present.
    • Outside Development, startup fails if ConnectionStrings:mailpit is set, so a stray setting can't divert real email away from Mailjet.
    • Production keeps using Mailjet unchanged.
  • Telemetry: exports MailKit's SMTP span source and SMTP/socket meters, so sends show up in the Aspire dashboard. The meters are created only when the MailPit sender is registered, and they record no email addresses or message content.

Tests

  • SmtpEndpointTests: connection-string parsing, including rejection of non-smtp schemes, missing or invalid ports and malformed strings.
  • EmailSenderStartupTests: which sender is chosen in Development with and without MailPit, and the startup failure outside Development.
  • IdentityEmailSmokeTests (AppHost, containers) check the actual requirements by signing in, not by page wording:
    • A user can't sign in before following the emailed confirmation link, and can sign in after.
    • After a reset through the emailed link, the new password works and the old one doesn't.
  • The email smoke tests share JourneyFixture (fake hCaptcha) but run in their own parallel group. Web's anonymous per-IP rate limit is shared by every 127.0.0.1 client, and overlapping these tests with the browser journeys used up that limit and made the journeys fail.

Local results: both builds pass, Web tests 385/385, AppHost tests 31/31 (Podman).

The standalone AppHost adds a MailPit container (CommunityToolkit 17.0.0,
persistent volume unless EphemeralDatabases) and references it from Web.

In Development, Web sends Identity email through a MailKit SmtpEmailSender
when it receives ConnectionStrings:mailpit; without it, Identity's no-op
sender still applies. Any other environment fails startup if the setting is
present and keeps using Mailjet unchanged. MailKit's SMTP span source and
SMTP/socket meters are exported; the meters are created only when the
MailPit sender is registered.

Smoke tests register a user and reset a password end to end, reading each
message from MailPit's API. They share JourneyFixture (fake hCaptcha) and run
in their own parallel group: Web's anonymous per-IP rate limit is shared by
every 127.0.0.1 client, and overlapping the browser journeys starved them.
…atch

Addresses the CodeQL generic-catch-clause alert in EmailSenderStartupTests.
@BenjaminMichaelis
BenjaminMichaelis merged commit e7f05f7 into main Nov 28, 2026
14 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the claude/mailpit-identity-emails branch November 28, 2026 20:58
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.

2 participants