spatie/laravel-mail-preview
Laravel mail transport to preview sent emails locally. Adds an in-browser overlay with a link to the last sent message, and lets you view rendered mail content in the browser. Ideal for development/testing; avoid in production.
preview driver, storing emails as .html/.eml files for inspection.APP_DEBUG), ensuring no risk of production interference.MailStoredEvent) for extensibility (e.g., custom storage, notifications).SentMails facade for assertion-based testing, addressing Laravel’s Mail::fake() limitations (e.g., content validation).config/mail.php to use preview transport.app/Http/Kernel.php.Route::mailPreview() in routes/web.php.storage_path('email-previews'); cleanup may be needed for long-running tests.SentMails assertions require actual mail sending (not Mail::fake()), which may slow tests.APP_DEBUG is properly gated.maximum_lifetime_in_seconds)?SentMails assertions? If so, benchmark performance vs. Mail::fake().composer require spatie/laravel-mail-preview
config/mail.php to use preview transport.php artisan vendor:publish --provider="Spatie\MailPreview\MailPreviewServiceProvider" --tag="mail-preview-config"
php artisan vendor:publish --provider="Spatie\MailPreview\MailPreviewServiceProvider" --tag="mail-preview-views"
AddMailPreviewOverlayToResponse to web middleware group in app/Http/Kernel.php.Route::mailPreview() in routes/web.php.Mail::fake() assertions with SentMails::assertSent() where content validation is needed.smtp, ses) by configuring each separately.SentMails assertions in PHPUnit.config/mail.php to original transport if issues arise.config/mail-preview.php.maximum_lifetime_in_seconds (default: 60s).storage/email-previews or implement a cron job for bulk cleanup.web group and route is registered.storage_path('email-previews') permissions.SentMails tests are not mixed with Mail::fake().show_link_to_preview is true and APP_DEBUG is true.storage/email-previews.maximum_lifetime_in_seconds..html/.eml files are small (typically <100KB each).storage/email-previews growth in CI/CD pipelines.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Middleware not registered | Overlay never appears | Verify Kernel.php and web group. |
| Storage path inaccessible | Emails not saved | Check permissions (chmod -R 755 storage). |
APP_DEBUG = false |
Preview disabled | Set enabled: true in config. |
| Laravel version incompatibility | Package fails to load | Pin to compatible version in composer.json. |
| Test assertions fail | Flaky tests | Use SentMails only for content checks. |
/spatie-mail-preview.SentMails facade enables content assertions.SentMails::assertSent().How can I help you explore Laravel packages today?