techinasia / laravel-mandrill-notification-channel
Laravel 5.3 的 Mandrill 通知通道
v1.0.0
2017-02-09 07:35 UTC
Requires
- php: >=5.6.4
- illuminate/notifications: ^5.3
- illuminate/queue: ^5.1|^5.2|^5.3
- illuminate/support: ^5.1|^5.2|^5.3
- mandrill/mandrill: ^1.0
Requires (Dev)
- mockery/mockery: ^0.9.5
- orchestra/testbench: ^3.3
- phpunit/phpunit: ^4.8
- satooshi/php-coveralls: ^1.0
This package is not auto-updated.
Last update: 2024-09-29 02:13:30 UTC
README
使用 Laravel 5.3 通知通过 Mandrill 发送邮件。
内容
安装
使用 Composer 安装此包
composer require techinasia/laravel-mandrill-notification-channel
在您的 config/app.php
中注册服务提供者
NotificationChannels\Mandrill\MandrillServiceProvider::class
设置 Mandrill
将您的 API 密钥添加到您的配置文件 config/services.php
'mandrill' => [ 'secret' => env('MANDRILL_SECRET', ''), ],
使用
在通知中通过 Mandrill 发送邮件
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']); } }
您需要通过在实体上定义一个 routeNotificationForMandrill
方法来指定可通知的电子邮件地址和名称
/** * Route notifications for the Mandrill channel. * * @return array */ public function routeNotificationForMandrill() { return [ 'email' => $this->email, 'name' => $this->name ]; }
您也可以通过提供一个类似于 Mandrill API 的 to[]
结构的列表来指定多个收件人
/** * 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)
: 设置消息的模板名称和内容。如果设置了此值,将使用send-template
而不是send
。
以下方法与从 Mandrill API 的 send
和 send-template
调用的参数相同。
async(bool $value = true)
: 启用后台发送模式,该模式针对批量发送进行了优化。ip_pool(string $name)
: 要发送消息应使用的专用 IP 池的名称。send_at(DateTime $datetime)
: 发送消息的日期/时间。对象将被转换为 UTC。
您可以通过调用以驼峰命名的方式命名的属性名称并使用值作为参数来设置 message
结构的任何属性。
return (new MandrillMessage()) ->subject('Test Subject') ->mergeLanguage('handlebars');
变更日志
有关最近更改的更多信息,请参阅变更日志。
测试
composer test
安全性
如果您发现任何与安全相关的问题,请通过电子邮件dev@techinasia.com报告,而不是使用问题跟踪器。
贡献
有关详细信息,请参阅贡献。
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅许可文件。