指南
- 介绍
- Contribute
- 部署
- 管理
- Advanced
进阶
- Main 核心概念
- 高级指引
- Advanced Guides
- Update Guides
- Extending Flarum
- Internal Team Docs
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
Mail Drivers
In addition to the default drivers in core, Flarum allows new mail drivers to be added through extenders. To create your own mail driver, you'll need to create a class implementing \Flarum\Mail\DriverInterface
. Flarum actually takes care of the frontend for providing email settings: just declare which settings you need, and any default values, in availableSettings
.
For example:
use Flarum\Mail\DriverInterface;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Mail\Transport\MailgunTransport;
use Illuminate\Support\MessageBag;
use Swift_Transport;
class MailgunDriver implements DriverInterface
{
public function availableSettings(): array
{
return [
'setting_one' => '',
'setting_two' => 'defaultValue',
'dropdown_setting' => [
'option_one_val' => 'Option One Display',
'option_two_val' => 'Option Two Display',
],
];
}
public function validate(SettingsRepositoryInterface $settings, Factory $validator): MessageBag
{
$validator->make($settings->all(), [
'setting_one' => 'required',
'setting_two' => 'nullable|integer',
])->errors();
}
public function canSend(): bool
{
return true;
}
public function buildTransport(SettingsRepositoryInterface $settings): Swift_Transport
{
// Return a mail transport that implements Swift Transport
}
}
To register mail drivers, use the Flarum\Extend\Mail
extender in your extension's extend.php
file:
use Flarum\Extend;
use YourNamespace\Mail\CustomDriver;
return [
// Other extenders
(new Extend\Mail())->driver(CustomDriver::class)
// Other extenders
];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论