Mailpit Documentation

repository·develop·Indexed 27 days ago

https://github.com/axllent/mailpit

Mailpit is a fast, low-memory, multi-platform email testing tool and API. It features an SMTP server to capture outgoing emails, a modern web UI for viewing messages, and a REST API for automated integration testing. The tool includes utility commands for dumping messages, ingesting email datasets, performing healthchecks via readyz, and reindexing the database. It supports configuration through CLI flags and environment variables, as well as SMTP relay, forwarding, and webhooks.

Tokens
5.3K
Snippets
5
Records
39
Agent score
95%

What's inside Mailpit

  1. Install Mailpit via package managers

    develop

    You can install Mailpit using the following package managers depending on your operating system:

    • Mac: Use Homebrew. To run it automatically in the background, use brew services start mailpit.
    • Arch Linux: Available in the AUR as mailpit.
    • FreeBSD: Use pkg install mailpit.
    brew install mailpit
    # To run automatically in the background:
    brew services start mailpit
    
    pkg install mailpit
    
    # Arch Linux (AUR)
    pkg install mailpit
  2. Install Mailpit via script (Linux & Mac)

    develop

    Linux and Mac users can install Mailpit directly to /usr/local/bin/mailpit using the official installation script.

    To specify a custom installation path, set the INSTALL_PATH environment variable.

  3. Configure your application to use Mailpit SMTP

    develop

    Mailpit acts as an SMTP server. By default, it listens on port 1025. To test email delivery, configure your application to send mail to 0.0.0.0:1025 (or the specific host where Mailpit is running).

    If your application uses sendmail (common in PHP applications), Mailpit can be configured as a substitute for the system's MTA.

  4. Run Mailpit or Sendmail

    develop

    The main package serves as the entrypoint for the Mailpit binary. The application determines which command to execute based on the name of the executable file:

    1. Sendmail mode: If the executable name contains the string send (case-insensitive, e.g., sendmail), the application runs the sendmail command.
    2. Mailpit mode: For any other executable name, the application runs the standard mailpit command.
  5. Use the Mailpit sendmail replacement CLI

    develop

    Mailpit provides a sendmail command replacement that acts as a drop-in for standard sendmail utilities. It can be used to pipe messages via standard input to an SMTP server or to handle a single SMTP session in the foreground using the -bs flag.

    Usage Modes

    1. Standard Mode: Read a message from stdin and send it to the specified SMTP server and recipients. [flags] [recipients] < message

    2. Interactive/Session Mode (-bs): Handle SMTP commands directly on standard input, mimicking a network SMTP session. This is useful for testing raw SMTP interactions. [flags] -bs < message

    Environment Variables

    You can configure the default behavior using these environment variables:

    • MP_SENDMAIL_SMTP_ADDR: Sets the default SMTP server address.
    • MP_SENDMAIL_FROM: Sets the default envelope sender address.
  6. Configure Mailpit via environment variables

    develop

    Mailpit supports configuration through environment variables, which is useful for Docker and CI/CD environments. Environment variables follow the MP_ prefix convention.

    Key environment variables include:

    • MP_DATABASE: Database file path.
    • MP_UI_BIND_ADDR: HTTP bind interface and port for UI.
    • MP_SMTP_BIND_ADDR: SMTP bind interface and port.
    • MP_MAX_MESSAGES: Maximum number of messages to store.
    • MP_MAX_AGE: Maximum age of messages (e.g., 3d).
    • MP_WEBHOOK_URL: URL to send a webhook request for new messages.
    • MP_ENABLE_PROMETHEUS: Enable Prometheus metrics (e.g., true or 0.0.0.0:9090).

    Note: Boolean flags can be enabled by setting the variable to 1, true, or yes.

  7. Configure ESLint for Mailpit

    develop

    Mailpit uses a flat configuration for ESLint that integrates recommended JavaScript rules, Vue-specific rules, and Prettier compatibility. It also respects the project's .gitignore file to prevent linting irrelevant files.

    Key configuration components:

    • Base Rules: Uses js.configs.recommended for .js and .vue files.
    • Vue Support: Includes vue.configs["flat/recommended"].
    • Formatting: Uses eslint-config-prettier/flat to disable rules that conflict with Prettier.
    • Custom Rules: Enforces strict coding standards including arrow functions, camelCase, dot notation, and security constraints like no-eval.
    import eslintConfigPrettier from "eslint-config-prettier/flat";
    import globals from "globals";
    import { includeIgnoreFile } from "@eslint/compat";
    import js from "@eslint/js";
    import vue from "eslint-plugin-vue";
    import { fileURLToPath } from "node:url";
    
    const gitignorePath = fileURLToPath(new URL(".gitignore", import.meta.url));
    
    export default [
    	includeIgnoreFile(gitignorePath, ".gitignore"),
    	{
    		files: ["**/*.js", "**/*.vue"],
    		languageOptions: { globals: { ...globals.browser, ...globals.node } },
    		rules: js.configs.recommended.rules,
    	},
    	...vue.configs["flat/recommended"],
    	eslintConfigPrettier,
    	{
    		rules: {
    			"prefer-arrow-callback": "error",
    			camelcase: [
    				"error",
    				{
    					ignoreDestructuring: false,
    					ignoreGlobals: true,
    					ignoreImports: false,
    					properties: "never",
    				},
    			],
    			"default-case-last": "error",
    			"dot-notation": "error",
    			eqeqeq: ["error", "smart"],
    			"no-eval": "error",
    			"no-implied-eval": "error",
    			"no-template-curly-in-string": "error",
    			"no-unneeded-ternary": "error",
    			"no-unused-expressions": "error",
    			"no-var": "error",
    			"object-shorthand": "error",
    			"prefer-const": "error",
    		},
    	},
    ];
  8. Start the Mailpit HTTP daemon

    develop

    Use the Listen() function to start the Mailpit HTTP server. This function initializes the WebSocket hub, starts the POP3 server, sets up API routes, handles Kubernetes health probes, and configures the web UI. It supports:

    • HTTP/HTTPS via standard TCP ports.
    • Unix Domain Sockets (if configured via config.HTTPListen).
    • TLS/SSL if config.UITLSCert and config.UITLSKey are provided.

    Note that Listen() is a blocking call that starts the server loop.