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.
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"
Nothing to do here! Simply install the package and we will start tracking outgoing email saving the results to your database.
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
});
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,
];
}
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.