This plugin provides a Mailtrap integration for Craft CMS. Mail is sent through the Mailtrap Email API over HTTPS, not SMTP.
This plugin requires Craft CMS 4.0.0+ or 5.0.0+, and PHP 8.0.2+.
Note for Craft 4: Craft 4 pins
twig/twigto a release that carries security advisories, and Composer 2.10 refuses to install such a package by default. That blocks creating a new Craft 4 project, before this plugin is involved at all. Adding the plugin to an existing Craft 4 site is unaffected: Composer keeps the version already incomposer.lockand only prints a warning. This is a constraint in Craft itself, not in this plugin.
You can install this plugin from the Plugin Store or with Composer.
Go to the Plugin Store in your project’s Control Panel and search for “Mailtrap”. Then click on the “Install” button in its modal window.
Open your terminal and run the following commands:
# go to the project directory
cd /path/to/my-project.test
# tell Composer to load the plugin
composer require yournextagency/craft-mailtrap
# tell Craft to install the plugin
./craft install/plugin mailtrapComposer and Craft both run inside the container, so prefix the commands:
ddev composer require yournextagency/craft-mailtrap
ddev craft install/plugin mailtrapOnce Mailtrap is installed, go to Settings → Email and change the “Transport Type” setting to “Mailtrap”. Enter the API token for your sending domain and click Save.
Tokens are created per sending domain, and a token needs admin permission on that
domain to send. The full token is shown only once, when it is created or reset —
so put it in your .env file right away.
| Setting | Required | Description |
|---|---|---|
| API Token | Yes | The API token for your sending domain. |
| Endpoint | No | Defaults to https://send.api.mailtrap.io. Set it to https://bulk.api.mailtrap.io to send over the bulk stream. |
| Inbox ID | No | When set, mail is delivered to that Mailtrap sandbox inbox instead of to real recipients. |
Endpoint and Inbox ID describe different destinations, so set one or the other, not both.
Tip: All three settings can be set to environment variables. See Environmental Configuration in the Craft docs to learn more about that.
Set Inbox ID to have Craft deliver into a Mailtrap inbox rather than to real recipients. That is useful on staging, where you want to see the mail your site sends without anyone receiving it.
Because the setting accepts an environment variable, one plugin configuration covers every environment:
# .env on staging — mail lands in inbox 1234567
MAILTRAP_TOKEN=your-token
MAILTRAP_INBOX_ID=1234567
# .env in production — mail is delivered for real
MAILTRAP_TOKEN=your-token
MAILTRAP_INBOX_ID=An unset or empty MAILTRAP_INBOX_ID means live sending.
Mailtrap is a trademark of its owner. This plugin is an unofficial integration and is not affiliated with, endorsed by, or sponsored by Mailtrap.