timfeid/slack-laravel-mail
Composer 安装命令:
composer require timfeid/slack-laravel-mail
包简介
Laravel Mail driver that delivers mail to your Slack server
README 文档
README
Set up
Installation
composer require timfeid/slack-laravel-mail
Add TimFeid\SlackLaravelMail\SlackMailServiceProvider::class, to your providers list in your app.php config.
TimFeid\SlackLaravelMail\SlackMailServiceProvider::class,
Config
Add the following config to your services.php config file.
'slackmail' => [ // The endpoint to your webhook 'endpoint' => env('SLACKMAIL_ENDPOINT', 'https://hooks.slack.com/services/..../....'), // The driver for which you would like to store emails // Drivers are 'cache' and 'file' for now 'driver' => env('SLACKMAIL_DRIVER', 'cache'), // Cache settings, will always use your default cache driver for now 'cache' => [ // Remove if you would not like to use cache()->tags() 'tag' => 'slack-mail', // Time you want to keep emails for in minutes 'ttl' => 60, ], 'file' => [ // File location you would like to save your emails 'location' => storage_path('/mail'), ], // From user for your Slack message 'from' => 'Emails', // Channel you'd like to send your messages to // @username to send private messages from @Slackbot 'channel' => env('SLACKMAIL_TO', '#emails'), // Fields you would like to show up in your message 'fields' => [ 'subject', 'to', 'cc', 'bcc', 'from', 'attachments', ], ],
Dot File (.env)
As you can probably tell, .env is encouraged for a per-environment setup
SLACKMAIL_ENDPOINT="https://hooks.slack.com/services..."
SLACKMAIL_DRIVER="cache"
SLACKMAIL_TO="@username"
MAIL_DRIVER="slack" # Activate slackmail as your mail driver
Route
Add this route to your routes file. The route can be set up however you'd like, but it must have slackmail as the name ->name('slackmail')
if (!app()->environment('production')) { Route::get('/slack-mail/{name}', '\TimFeid\SlackLaravelMail\Controllers\SlackMailController@slackMail') ->name('slackmail'); }
Extending the fields
You'll want to create service provider that extends SlackMailServiceProvider and overwrite the registerSlackFields method.
<?php namespace App\Providers; use App\Services\Slack\SlackFields; use TimFeid\SlackLaravelMail\SlackMailServiceProvider as BaseProvider; class SlackMailServiceProvider extends BaseProvider { public function registerSlackFields() { $this->app->singleton('slackmail.fields', SlackFields::class); } }
Example SlackFields class
<?php namespace App\Services\Slack; use TimFeid\SlackLaravelMail\SlackFields as BaseSlackFields; class SlackFields extends BaseSlackFields { public function buildSendgridField() { return [ 'title' => 'Sendgrid Headers', 'value' => '```'.json_encode([ 'categories' => $this->message->getCategories(), 'custom_args' => $this->message->getArguments(), ], JSON_PRETTY_PRINT).'```', ]; } }
timfeid/slack-laravel-mail 适用场景与选型建议
timfeid/slack-laravel-mail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.93k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 05 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 timfeid/slack-laravel-mail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 timfeid/slack-laravel-mail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-16
