hakito/ cakephp-mailqueue-plugin
插件,用于将邮件存储在队列中以便稍后发送
v5.0
2024-01-02 20:31 UTC
Requires
- cakephp/cakephp: ^5.0
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-04 21:28:54 UTC
README
CakePHP 5.x 插件,用于将邮件存储在队列中以便稍后发送。
在与 Web 服务协同工作时,发送邮件会阻塞 HTTP 请求,直到邮件真正发送出去。如果 SMTP 服务器没有及时响应,这可能会让用户感到沮丧。
使用此插件,您可以将邮件保存到本地队列文件,并通过例如通过定时触发的 cake 壳命令来调用实际传输。
安装
如果您使用 composer,只需添加即可
composer require hakito/cakephp-mailqueue-plugin
否则,请将插件下载到 app/Plugin/Mailqueue。
在您的引导方法中加载插件
$this->addPlugin('MailQueue');
配置
将传输条目添加到您的 app_local.php
'EmailTransport' => [ 'MailQueue' => [ // required 'className' => \MailQueue\Mailer\Transport\QueueTransport::class, 'queueFolder' => TMP . 'mailqueue', // storage location for mailqueue // optional: 'requeue' => [300, 500, 1000] // requeue after x seconds in case of an error ] ], 'Email' => [ 'default' => [ 'transport' => 'MailQueue', ], 'smtp' => [ // configure your real mailer here ] ]
队列邮件
在 cake 中像往常一样将邮件发送到队列
$mailer = new Mailer('default'); // place your content in $email $mailer->deliver();
执行实际发送
使用 cake 壳执行实际发送。该 shell 脚本需要两个参数。第一个是您的队列配置名称,第二个是用于实际发送的配置名称。
在您的应用目录中执行
bin/cake MailQueue SendMail smtp