https://github.com/modernmcguire/mailspy
MailSpy is a Laravel package that allows you to capture and inspect emails sent by your application.
https://github.com/modernmcguire/mailspy
debug laravel logging logs mail retention
Last synced: about 1 year ago
JSON representation
MailSpy is a Laravel package that allows you to capture and inspect emails sent by your application.
- Host: GitHub
- URL: https://github.com/modernmcguire/mailspy
- Owner: modernmcguire
- License: mit
- Created: 2024-02-28T22:28:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-12T08:41:05.000Z (about 1 year ago)
- Last Synced: 2025-05-12T09:58:49.403Z (about 1 year ago)
- Topics: debug, laravel, logging, logs, mail, retention
- Language: PHP
- Homepage: https://modernmcguire.com
- Size: 85 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# MailSpy
[](https://packagist.org/packages/modernmcguire/mailspy)
[](https://github.com/modernmcguire/mailspy/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/modernmcguire/mailspy/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[](https://packagist.org/packages/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.
---
Do you want to fully capture your emails as an alternative to the log driver? Try out [MailThief](https://github.com/modernmcguire/mailthief).
---
## Installation
You can install the package via composer:
```bash
composer require modernmcguire/mailspy
```
You can publish and run the migrations with:
```bash
php artisan vendor:publish --tag="mailspy-migrations"
php artisan migrate
```
You can publish the config file with:
```bash
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.
```php
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.
```php
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
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Ben Miller](https://github.com/modernben)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.