Skip to content

Proposal to Add Email Testing Documentation #113

@ozgursar

Description

@ozgursar

Problem

The Test Handbook's "Get Set Up for Testing" section doesn't include guidance on testing email functionality in WordPress. Certain core tickets involve email features (user registration, password resets, notifications, contact forms), but contributors don't have documentation on how to test these locally or using the WordPress Playground.

Proposed Solution

Add a new page under "Get Set Up for Testing" that covers email testing strategies for WordPress contributors, including:

  • Why email testing is important for WordPress testing
  • Different approaches for different environments (local, Playground)
  • How to set up Mailpit for local email testing (via Docker)
  • How to configure WordPress Develop to use SMTP service and point to Mailpit
  • How to verify emails are being captured
  • Common use cases (testing wp_mail, contact forms, user notifications)

Email Testing Methods

1. Email Logging MU-Plugin (Suitable for all environments)

A lightweight mu-plugin that logs all outgoing emails for debugging:

  • Works in all environments (local and Playground)
  • No external dependencies or configuration needed
  • Logs to file and/or admin UI
  • Shows recipient, subject, timestamp, delivery status
  • Can view full email content (HTML/text)
  • Especially useful for WordPress Playground where other tools aren't available

Sample plugin for single-site installations:
https://gist.github.com/ozgursar/64fd58d2fc5b0aca62487cdc9493e8a4

Sample plugin for multi-site installations:
https://gist.github.com/ozgursar/ec4997827c49f7348aff6c52704454a1

Benefits:

  • Simplest setup - just drop in wp-content/mu-plugins/
  • Works everywhere WordPress runs
  • Helps verify emails are being triggered even if not actually sent
  • Perfect for quick ticket testing

2. Mailpit (Suitable for local environment running Docker)

For developers who want to see full email rendering with a GUI:

  • Modern, actively maintained (unlike deprecated MailHog)
  • Zero configuration SMTP server
  • Web UI to view HTML emails, inspect headers, test responsiveness
  • Works with Docker/wp-env
  • Requires local environment setup

Proposed setup instructions:

  • Create docker-compose.override.yml with the following code in root folder of your cloned wordpress develop repo
services:
  mail:
    container_name: mailpit
    image: axllent/mailpit
    restart: unless-stopped
    ports:
      - "1025:1025" # smtp server
      - "8025:8025" # web ui
    environment:
      MP_MAX_MESSAGES: 5000
      MP_SMTP_AUTH_ACCEPT_ANY: 1
      MP_SMTP_AUTH_ALLOW_INSECURE: 1
    networks:
      - wpdevnet
  • Run the command: docker compose up -d mail
  • Test access to mailpit: http://localhost:8025/
  • Add the following snippet to functions.php or via Code Snippets plugin to intercept mails via Mailpit:
add_action( 'phpmailer_init', function( $phpmailer ) {
    $phpmailer->isSMTP();
    $phpmailer->Host = 'localhost';
    $phpmailer->Port = 1025;
} );

add_filter( 'wp_mail_from', function( $email ) {
    return 'noreply@example.com';
});

Props to @SirLouen for Mailpit setup

Proposed Location

Add as a new page: /get-setup-for-testing/email-testing.md
Or as a new section in the existing /get-setup-for-testing/index.md

References

Metadata

Metadata

Assignees

No fields configured for Enhancement.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions