Skip to content

Add MailPit email catching integration - #3913

Draft
youknowriad wants to merge 7 commits into
trunkfrom
add-mailpit-integration
Draft

Add MailPit email catching integration#3913
youknowriad wants to merge 7 commits into
trunkfrom
add-mailpit-integration

Conversation

@youknowriad

@youknowriad youknowriad commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Related issues

Closes #24

How AI was used in this PR

This PR was opened with AI assistance to surface and revive existing work: an agent located the dormant add-mailpit-integration branch, mapped the implementation against Studio's two PHP runtimes, identified gaps, and drafted this description. The implementation itself is entirely @ryanr14's — all commits are authored by him and unchanged. No AI-generated code has been added on top.

Proposed Changes

Adds local email testing to Studio, so messages sent by a site never leave the machine and can be inspected in a real inbox UI — the capability Studio is missing compared with tools like Local and Cove.

  • Studio bundles and runs Mailpit per site, exposing a web inbox plus an SMTP endpoint for manual testing.
  • Outgoing wp_mail() messages (recipients, CC/BCC/Reply-To, custom headers, HTML/text body, attachments) are captured and routed to the local Mailpit inbox instead of being delivered.
  • Capture works in both the WordPress Playground (PHP-WASM) and native-PHP runtimes by forwarding mail to Mailpit's HTTP send API from a must-use plugin, rather than relying on outbound SMTP (which PHP-WASM cannot do).
  • The desktop app gains an "Email Inbox" shortcut on the site Overview and an "Email testing" section in Settings (open inbox, copyable SMTP host/port).

⚠️ Visual change: needs human review in light + dark mode.

Known gaps before this is merge-ready

  • Mailpit is currently enabled for every new site with no opt-in/opt-out flag, and existing sites are not backfilled.
  • No CLI surface yet (no studio mail command; the inbox isn't referenced in site status) — capture works headless but is only discoverable from the desktop app.
  • Branch predates ~1 month of trunk movement (incl. CLI subcommand restructuring) and needs a rebase + full typecheck/test pass.

Testing Instructions

  1. npm run download-mailpit (or a full npm install) to fetch the Mailpit binary for your platform.
  2. Create a new site and start it.
  3. Trigger an email (e.g. trigger a password reset, or studio wp eval 'wp_mail("to@example.com","Hello","Body");').
  4. Open the site's Email Inbox (Overview shortcut or Settings → Email testing) and confirm the message appears with correct subject/recipients/body.
  5. Repeat under both runtimes (Playground and native PHP) if possible.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

🤖 Generated with Claude Code

ryanr14 added 4 commits May 12, 2026 15:31
# Conflicts:
#	apps/cli/commands/wp.ts
#	apps/cli/lib/run-wp-cli-command.ts
#	apps/cli/php-server-child.ts
#	tools/common/lib/mu-plugins.ts
youknowriad and others added 3 commits June 22, 2026 11:25
Resolve conflicts from trunk's CLI refactors (native-PHP worker pool,
runtime threading via getSiteRuntime, tsx tooling) while preserving the
MailPit email-catching integration.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The npm-published CLI ships cross-platform and cannot bake in a native
MailPit binary for every OS/arch, so only the publish platform worked.
Resolve the bundled (desktop) binary first and otherwise fetch the
matching release asset into ~/.studio on first use, mirroring the native
PHP binary pattern. Drop the build-time download from the root
postinstall so the npm tarball stays lean; desktop packaging still
bundles per-platform via forge.config.ts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@youknowriad

Copy link
Copy Markdown
Contributor Author

For context, I think this is a strong feature, I didn't implement this myself, it's based on @ryanr14's work but I believe we should consider helping moving it forward. I've seen a lot of people request this. It's a gap compared to other tools.

@fredrikekelund

Copy link
Copy Markdown
Contributor

Acknowledging that I've seen this, but also that I won't be able to review it until next week.

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Riad, thanks for moving this integration forward. I agree that this is a feature many users have requested and it will be useful for them.

I just noticed a couple of things:

  • When deleting a site we might want to remove the emails related to it in ~/.studio/mailpit/${siteId}.db and similar files
  • Running nvm use && npm i && npm start was not enough and resulted in http://127.0.0.1:8025/ returning an error/empty page. It worked correctly after running npm run download-mailpit once.

I tried reseting the password of admin@localhost.com:
Image
Image

I'll be AFK tomorrow and next week, so I won't be able to review or help with this PR until I come back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants