Mailpit Documentation
repository·develop·Indexed 27 days ago
https://github.com/axllent/mailpitMailpit 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.
What's inside Mailpit
- Multi-architecture Docker images (386, amd64, and arm64) are available for Mailpit. Refer to the official Docker documentation for specific instructions.
Install Mailpit via package managers
developYou 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- Mac: Use Homebrew. To run it automatically in the background, use
Install Mailpit via static binary
developStatic binaries for Windows, Linux, and Mac can be downloaded from the latest releases. You can extract themailpitbinary and add it to your$PATHor run it directly using./mailpit.Install Mailpit via script (Linux & Mac)
developLinux and Mac users can install Mailpit directly to
/usr/local/bin/mailpitusing the official installation script.To specify a custom installation path, set the
INSTALL_PATHenvironment variable.Configure your application to use Mailpit SMTP
developMailpit acts as an SMTP server. By default, it listens on port
1025. To test email delivery, configure your application to send mail to0.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.Run Mailpit or Sendmail
developThe
mainpackage serves as the entrypoint for the Mailpit binary. The application determines which command to execute based on the name of the executable file:- Sendmail mode: If the executable name contains the string
send(case-insensitive, e.g.,sendmail), the application runs thesendmailcommand. - Mailpit mode: For any other executable name, the application runs the standard
mailpitcommand.
- Sendmail mode: If the executable name contains the string
Use the Mailpit sendmail replacement CLI
developMailpit provides a
sendmailcommand 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-bsflag.Usage Modes
Standard Mode: Read a message from
stdinand send it to the specified SMTP server and recipients.[flags] [recipients] < messageInteractive/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.
Configure Mailpit via environment variables
developMailpit 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.,trueor0.0.0.0:9090).
Note: Boolean flags can be enabled by setting the variable to
1,true, oryes.Configure ESLint for Mailpit
developMailpit uses a flat configuration for ESLint that integrates recommended JavaScript rules, Vue-specific rules, and Prettier compatibility. It also respects the project's
.gitignorefile to prevent linting irrelevant files.Key configuration components:
- Base Rules: Uses
js.configs.recommendedfor.jsand.vuefiles. - Vue Support: Includes
vue.configs["flat/recommended"]. - Formatting: Uses
eslint-config-prettier/flatto 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", }, }, ];- Base Rules: Uses
Run Mailpit and view options
developOnce installed, you can run Mailpit from your terminal. Use the
-hflag to view all available runtime options and configuration settings.mailpit -hStart the Mailpit HTTP daemon
developUse 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.UITLSCertandconfig.UITLSKeyare provided.
Note that
Listen()is a blocking call that starts the server loop.Establish a POP3 connection
developOnce aClientis initialized, callNewConn()to establish a live connection to the POP3 server. This method returns a*Connobject which represents the stateful connection and handles command execution.