modernmcguire / mailspy
MailSpy is a Laravel package that allows you to capture and inspect emails sent by your application. It was created to help with testing and debugging email sending in Laravel applications in addition to getting around low retention log limits in services like MailGun and MailerSend.
Fund package maintenance!
ModernMcGuire
Installs: 3 025
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.20
- pestphp/pest-plugin-arch: ^2.5
- pestphp/pest-plugin-laravel: ^2.0
README
MailSpy is a Laravel package that allows you to capture and inspect emails sent by your application. It was created to help with testing and debugging email sending in Laravel applications in addition to getting around low retention log limits in services like MailGun and MailerSend.
Do you want to fully capture your emails as an alternative to the log driver? Try out MailThief.
Installation
You can install the package via composer:
composer require modernmcguire/mailspy
You can publish and run the migrations with:
php artisan vendor:publish --tag="mailspy-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="mailspy-config"
Usage
Nothing to do here! Simply install the package and we will start tracking outgoing email saving the results to your database.
Events
MailSpy listens for the MessageSending and MessageSent events.
You may register your own event listeners by calling the Mailspy::sending()
and Mailspy::sent()
methods in a service provider.
use ModernMcGuire\MailSpy\Facades\MailSpy; use \Illuminate\Mail\Events\MessageSending; use \Illuminate\Mail\Events\MessageSent; MailSpy::sending(function (MessageSending $event, Email $email) { // Do something with the event }); MailSpy::sent(function (MessageSent $event, Email $email) { // Do something with the event });
Tags
If you want to tag your emails, you can do so by adding the MailspyTags
concern to any of your mailable classes.
use ModernMcGuire\MailSpy\Facades\MailSpy; use ModernMcGuire\MailSpy\Traits\MailspyTags; class MarketingPlan extends Mailable implements ShouldQueue { use Queueable; use SerializesModels; use MailspyTags; /** * Create a new message instance. * * @return void */ public function __construct( public Client $client, ) { // } public function tags(): array { return [ 'client' => $this->client->id, ]; } }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.