Skip to content

techinasia/laravel-mandrill-notification-channel

Repository files navigation

Mandrill Notification Channel for Laravel

Dependency Status Build Status Coverage Status StyleCI Status

Use Laravel 5.3 notifications to send mail via Mandrill.

Contents

Installation

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

Setting up Mandrill

Add your API key to your configuration at config/services.php:

'mandrill' => [
    'secret' => env('MANDRILL_SECRET', ''),
],

Usage

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' => '[email protected]',
            'name' => 'User A',
            'type' => 'to',
        ],
        [
            'email' => '[email protected]',
            'name' => 'User B',
            'type' => 'cc',
        ]
    ];
}

Available Message methods

  • template(string $name, array $content): Sets the template name and content of the message. If this is set, send-template will be used instead of send.

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');

Changelog

Please see CHANGELOG for more information for what has changed recently.

Testing

composer test

Security

If you discover any security related issues, please email [email protected] instead of using the issues tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Mandrill Notifications Channel for Laravel 5.3

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages