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.

0.2.2 2024-04-16 04:04 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.

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.