codewiser/laravel-sendsay-mailer

SendSay邮件器用于Laravel

v1.1.0 2024-03-12 15:38 UTC

This package is auto-updated.

Last update: 2024-09-12 16:36:58 UTC


README

此包为您的Laravel项目添加了一个邮件器 —— https://sendsay.ru服务。

它支持个人和批量发送邮件。

免责声明

此邮件器针对非常具体的任务进行了测试,因此我们无法保证它符合您的期望。

安装

只需从composer安装包。

配置

sendsay部分添加到应用程序的mail.mailers配置中

'sendsay' => [
    'transport' => 'sendsay',
    'endpoint' => env('SENDSAY_URL', 'https://api.sendsay.ru/general/api/v100/json'),
    'login' => env('SENDSAY_LOGIN'),
    'password' => env('SENDSAY_PASS'),
    'sub_login' => env('SENDSAY_SUBLOGIN', ''),
],

服务将写入到mail.mailers.log.channel配置中定义的通道的信息/错误日志。

最后,将MAIL_MAILER=sendsay设置到您的.env文件中。

批量发送

组合带有多个收件人的Mailable并发送它

use \Illuminate\Support\Facades\Mail;

$recipients = [
    'foo@example.com',
    'bar@example.com',
];

Mail::send(new CustomMailable($recipients));

个人发送

组合只带有一个收件人的Mailable或使用Notification

获取响应

将邮件器响应通过外观返回到应用程序的唯一方法(我发现)是将响应作为\Symfony\Component\Mailer\SentMessage的调试信息附加

use \Illuminate\Support\Facades\Mail;
use \Illuminate\Mail\Events\MessageSent;

$recipients = [
    'foo@example.com',
    'bar@example.com',
];

Event::listen(MessageSent::class, function (MessageSent $event) {
    // json encoded response
    dump($event->sent->getDebug());
});

Mail::send(new CustomMailable($recipients));