lacodix / laravel-scoped-mail-config
A package that enables user or tenant specific mail driver configuration.
Fund package maintenance!
lacodix
Installs: 167
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:laravel-package
Requires
- php: ^8.1
- illuminate/contracts: ^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- illuminate/database: ^9.47|^10.0|^11.0
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0|^7.8|^8.0
- nunomaduro/phpinsights: ^2.6
- orchestra/testbench: ^7.19|^8.8|^9.0
- pestphp/pest: ^1.21|^2.20
- pestphp/pest-plugin-laravel: ^1.1|^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-12-15 14:46:11 UTC
README
This package makes it an ease to send mails with dynamic mail configuration. The mail configuration can be provided by any model or class, that implements our HasMailConfig Interface.
With this in mind it is the perfect fit for multi tenancy packages like Laravel-multitenancy by spatie.
It also offers the possibility to keep mail configs in user or team models or even if you just want to be able to offer your admin-user to set a dynamic mail configuration.
Documentation
You can find the entire documentation for this package on our documentation site
Installation
composer require lacodix/laravel-scoped-mail-config
Basic Usage
Just add our interface to your scope model
use Illuminate\Database\Eloquent\Model; use Lacodix\LaravelScopedMailConfig\Concerns\HasMailConfig; class Tenant extends Model implements HasMailConfig { public function getMailConfig($name): array { return [ 'transport' => 'smtp', 'host' => 'my.smtp.server', 'port' => 587, 'encryption' => null, 'username' => 'my@email.login', 'password' => 'mypassword', 'timeout' => 60, 'local_domain' => null, 'from' => [ 'address' => 'my@email.login', 'name' => 'myname', ], ]; } }
In your AppServiceProvider you now just need to inform the package how it shall resolve the mail configuration. By default the Package resolves the current authenticated user. So if you want to use user specific mail configuration then just skip this step.
use Lacodix\LaravelScopedMailConfig\Facades\ScopedMail;
public function register(): void
{
ScopedMail::resolveScopeUsing(fn () => Tenant::getCurrentTenant());
}
Then you can send mails with this dynamic configuration just by using our facade like laravel Mail facade:
ScopedMail::to('my@email.de')->send($mailable);
ScopedMail is just extending standard Mail facade, so there are all functionalities, that you already know from laravel Mail
Finally it is also possible to use this facade in tests
ScopedMail::fake();
Testing
composer test
Contributing
Please run the following commands and solve potential problems before committing and think about adding tests for new functionality.
composer rector:test composer insights composer csfixer:test composer phpstan:test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.