返回介绍

Mail Drivers

发布于 2021-11-04 22:44:46 字数 2206 浏览 845 评论 0 收藏 0

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文