This package contains a Nova action that provides a mail sending form for any resource to easily send email. It also includes automated mail sending based on Eloquent Model events/attribute changes.
This Nova package requires Nova 2.0 or higher.
Using the mail delay feature requires a queue driver other than sync. If you are using the Amazon SQS queue service, the maximum delay time is 15 minutes.
You can install this package in a Laravel app that uses Nova via composer:
composer require kirschbaum-development/nova-mail
Next, we need to run migrations. Auto-discovery of this package's service provider helps with that!
php artisan migrate
And lastly, any model that you want to send mail needs the Mailable
trait added to it. The model should have a compliant email column. You also need to implement the abstract method provided by the Mailable
trait, like shown below. You should customize this if your email column name is different:
use KirschbaumDevelopment\NovaMail\Traits\Mailable;
class User extends Model
{
use Mailable;
/**
* Get the name of the email field for the model.
*
* @return string
*/
public function getEmailField(): string
{
return 'email';
}
// ...
}
If you would like to publish the config for this package, run:
php artisan vendor:publish
And choose the provider for this package: KirschbaumDevelopment\NovaMail\NovaMailServiceProvider
There is a single action (SendMail
) and two resources (NovaMailTemplate
and NovaSentMail
) that ship with this package. Internally the SendMail
action uses a custom Nova field to display the inline mail sending form.
The SendMail
action inserts a mail form directly into a Nova action modal. This action allows you to quickly send an email directly to one or more resources.
Simply add the KirschbaumDevelopment\NovaMail\Actions\SendMail
action to your Nova resource:
namespace App\Nova;
use KirschbaumDevelopment\NovaMail\Actions\SendMail;
class User extends Resource
{
// ...
public function actions(Request $request)
{
return [
// ...
new SendMail,
];
}
}
Now you can send emails from the action called "Send Mail" on your resource!
You can also delay any outgoing email by setting the delay in minutes property on the template. Like subject and body, you can override the mail delay specified in the template when you send mail.
A MailTemplate
can be configured to respond to Eloquent Model events, or a value change of a specified column. For example, a mail template informing your users of their account status could be sent when the active
column on your User
model is updated:
You can even have separate Model Events for both "on" an "off"!
The NovaMailTemplate
resource allows you to create re-usable custom templates for sending email. It works by taking your specified template (or over-ridden template content) and building a temporary blade file (the Blade file can be saved permantely via a configuration option). This blade file is then used in the typical Laravel fashion to send the email.
The final content provided when the user clicks the "Send Mail" button is parsed as markdown and makes no assumptions about newlines or any other formatting for that matter. For example, if you were to use the built in mail message component provided by Laravel for markdown emails you could create a template like the following:
@component('mail::message')
Hello {{ $name }},
Visit this link when you have a moment:
[https://github.com/kirschbaum-development/nova-mail](https://github.com/kirschbaum-development/nova-mail)
Let me know if you have any questions.
@include('path.to.footer')
@endcomponent
The NovaSentMail
resource can be added as a relationship field to any Resource
that has the Mailable
trait defined on it's corresponding model. This gives you direct access to the history of emails sent from that Resource
:
namespace App\Nova;
use Laravel\Nova\Fields\HasMany;
use KirschbaumDevelopment\NovaMail\Nova\NovaSentMail;
class User extends Resource
{
// ...
public function fields(Request $request)
{
return [
// ...
HasMany::make('Sent Mail', 'mails', NovaSentMail::class),
// ...
];
}
}
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email adam@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker.
Development of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more about us or join us!
The MIT License (MIT). Please see License File for more information.