twenty20 / mailer
A multi-provider mailer package for SendGrid, Amazon SES.
Installs: 480
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/twenty20/mailer
Requires
- php: ^8.2
- illuminate/contracts: ^9.0|^10.0|^11.0|^12.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
- laravel/prompts: *
- sendgrid/sendgrid: ^8.1
- spatie/laravel-package-tools: ^1.16
- symfony/mailer: ^6.0|^7.2
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^6.0|^7.0|^8.0
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0
- pestphp/pest: ^1.19|^2.0|^3.0
- pestphp/pest-plugin-laravel: ^v1.4.0|^2.0|^3.0
README
Mailer Package
A multi-provider mailer package supporting SendGrid and Amazon SES.
Installation
Install the package via Composer:
composer require twenty20/mailer
Once installed, run the following command to complete the setup:
php artisan mailer:install
Specify the webhook URL in your choosen provider to:
http://yourdomain.com/mailer/webhook
mailer/webhook
will be injected into your web.php
routes from the installer.
Usage
The package provides Events & Listeners.
Register these listeners in EventServiceProvider.php
protected $listen = [ EmailBounced::class => [ EmailBouncedListener::class, ], EmailDelivered::class => [ EmailDeliveredListener::class, ], EmailDeferred::class => [ EmailDeferredListener::class, ], .... ];
For Laravel 11 & above you can register events and their corresponding listeners within the boot
method of your application's AppServiceProvider
:
public function boot(): void { Event::listen( EmailBounced::class, EmailBouncedListener::class, ); Event::listen( EmailDelivered::class, EmailDeliveredListener::class, ); Event::listen( EmailDeferred::class, EmailDeferredListener::class ); .... }
These events will be triggered from the WebhookController.
Package ships with Listeners for each event which allows you to hook into and handle as required.
You will need to run php artisan queue:work
to see any events in the logs whilst testing locally.
Lastly within your VerifyCSRFToken middleware, add the following:
protected $except = [ 'mailer/*', ];
Or if using a later version of Laravel, in bootstrap/app.php
->withMiddleware(function (Middleware $middleware) { $middleware->validateCsrfTokens(except: [ 'mailer/*', ]); })->withExceptions(function (Exceptions $exceptions) { // })->create();
After installation, add your chosen provider’s API key to the .env
file, and you’re good to go.
You can then send emails and notifications as usual within your Laravel application.
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.