Filament Dynamic Mail Manager is a Filament plugin that allows you to manage mailer configurations in the database in addition to those defined in the Laravel configuration.
This enables sending emails using dynamic configurations tied, for example, to a user or an entity.
Before use composer
to install this package you need to add this package to your composer.json
file :
{ "repositories": [ { "type": "composer", "url": "https://filament-dyn-mail-manager.composer.sh" } ]}
Once the repository has been added to your composer.json
file, you can install this package via composer require
command:
To install the plugin, you can use Composer:
composer require yebor974/filament-dyn-mail-manager
You will be prompted to provide your username and password:
Loading composer repositories with package informationAuthentication required (filament-dyn-mail-manager.composer.sh):Username: [licensee-email]Password: [license-key]
The username will be your email address and the password will be equal to your license key, followed by a colon (:), followed by the domain you are activating. For example:
Loading composer repositories with package informationAuthentication required (filament-dyn-mail-manager.composer.sh):Username: your_email@domain.tldPassword: 8c21df8f-6273-4932-b4ba-8bcc723ef500:domain.tld
php artisan vendor:publish --tag="filament-dyn-mail-manager-config"
In config file, you have some default mailers, you can restrict or add mailers with default config keys like this :
'smtp' => [ 'transport' => 'smtp', 'url' => null, 'host' => null, 'port' => null, 'encryption' => null, 'username' => null, 'password' => null, 'timeout' => null, 'local_domain' => null,]
To use some mailers you have to install some packages like
symfony/mailgun-mailer
symfony/http-client
for mailgun. Please refer to the Laravel Mail documentation.
php artisan vendor:publish --tag="filament-dyn-mail-manager-migrations"php artisan migrate
By default,
DynMailManagerMailer
Model is used. You can defined yours in config file.
Optionally, you can publish translations files with:
php artisan vendor:publish --tag="filament-dyn-mail-manager-translations"
use Yebor974\FilamentDynMailManager\DynMailManagerPlugin; public function panel(Panel $panel): Panel{ return $panel ->plugins([ DynMailManagerPlugin::make() ])}
DynMailManagerMailableContract
on your mailable Model and implements methods. Example with an Entity model :use Yebor974\FilamentDynMailManager\Contracts\DynMailManagerMailableContract; class Entity extends Model implements DynMailManagerMailableContract{ ...}
You can use default HasDynMailManagerMailers
trait on your mailable Model;
use Yebor974\FilamentDynMailManager\Contracts\DynMailManagerMailableContract;use Yebor974\FilamentDynMailManager\Traits\HasDynMailManagerMailers; class Entity extends Model implements DynMailManagerMailableContract{ use HasDynMailManagerMailers;}
Or you can define the needed relation dynMailManagerMailers
function:
use Yebor974\FilamentDynMailManager\Contracts\DynMailManagerMailableContract;use Yebor974\FilamentDynMailManager\Traits\HasDynMailManagerMailers; class Entity extends Model implements DynMailManagerMailableContract{ use HasDynMailManagerMailers; public function dynMailManagerMailers(): MorphMany { return $this->morphMany( config('filament-dyn-mail-manager.models.dynMailManagerMailer'), 'mailable' ); }}
use Yebor974\FilamentDynMailManager\Resources\MailableResource\RelationManagers\DynMailManagerDriversRelationManager; public static function getRelations(): array{ return [ //... DynMailManagerDriversRelationManager::make() ];}
Each created configuration generates a slug that must be used when calling the method to send an email.
You have all the Laravel mail system. For example you can :
public function toMail(object $notifiable): MailMessage{ return (new MailMessage) ->mailer('{YOUR_SLUG_MAILER}') //...}
Example:
use Illuminate\Support\HtmlString;use Yebor974\FilamentDynMailManager\Models\DynMailManagerMailer class ExampleNotification extends Notification implements ShouldQueue{ use Queueable; public function __construct(protected DynMailManagerMailer $mailer) { $this->afterCommit(); } public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->mailer($this->mailer->slug) //... } //...}
use Illuminate\Support\Facades\Mail; Mail::mailer('{YOUR_SLUG_MAILER}')->send(...);
if slug is not found in database, the
MailManager
will try to find config on laravel mails config file.
Please see CHANGELOG for more information on what has changed recently.
If you discover any security related issues or need support, please email me at contact@julienboyer.re
We offer three types of licenses for our plugin:
For detailed terms and conditions, please see License Options.
you can test your mailer with the action table button
Send Test Email Action
No-reply values are not mandatory