Use Laravel 5.3 notifications to send mail via Mandrill.
Install this package with Composer:
composer require techinasia/laravel-mandrill-notification-channel
Register the service provider in your config/app.php
:
NotificationChannels\Mandrill\MandrillServiceProvider::class
Add your API key to your configuration at config/services.php
:
'mandrill' => [
'secret' => env('MANDRILL_SECRET', ''),
],
Send mails via Mandrill in your notification:
use NotificationChannels\Mandrill\MandrillChannel;
use NotificationChannels\Mandrill\MandrillMessage;
use Illuminate\Notifications\Notification;
class TestNotification extends Notification
{
public function via($notifiable)
{
return [MandrillChannel::class];
}
public function toMandrill($notifiable)
{
return (new MandrillMessage())
->template('foo-bar', ['foo' => 'bar']);
}
}
You need to specify the email address and name of the notifiable by defining a routeNotificationForMandrill
method on the entity:
/**
* Route notifications for the Mandrill channel.
*
* @return array
*/
public function routeNotificationForMandrill()
{
return [
'email' => $this->email,
'name' => $this->name
];
}
You can also specify multiple recipients by supplying an list similar to the to[]
struct of Mandrill API:
/**
* Route notifications for the Mandrill channel.
*
* @return array
*/
public function routeNotificationForMandrill()
{
return [
[
'email' => 'a@bar.com',
'name' => 'User A',
'type' => 'to',
],
[
'email' => 'b@bar.com',
'name' => 'User B',
'type' => 'cc',
]
];
}
template(string $name, array $content)
: Sets the template name and content of the message. If this is set,send-template
will be used instead ofsend
.
The following methods work the same as the parameters in send
and send-template
calls from the Mandrill API.
async(bool $value = true)
: Enable a background sending mode that is optimized for bulk sending.ip_pool(string $name)
: Name of the dedicated ip pool that should be used to send the message.send_at(DateTime $datetime)
: Date / time of when to send the message. Object will be converted to UTC.
You can set any attributes of the message
struct by calling the name of attribute in camel case with the value as the parameter:
return (new MandrillMessage())
->subject('Test Subject')
->mergeLanguage('handlebars');
Please see CHANGELOG for more information for what has changed recently.
composer test
If you discover any security related issues, please email dev@techinasia.com instead of using the issues tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.