adt / mail-queue
终极Nette邮件解决方案。
v1.8
2024-06-05 02:23 UTC
Requires
- php: ^7.1|^8.0
- adt/background-queue: ^4.22
- nette/di: ^2.3 || ~3.0
- nette/mail: ~3.0
- tracy/tracy: ^2.3
- dev-master
- v1.8
- v1.7.2
- v1.7.1
- v1.7
- v1.6.4
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6
- v1.5.1
- v1.5
- v1.4
- v1.3
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1
- v1.0.0
- dev-bq-priorities
- dev-fix-publish-background-queue-parameters-1
- dev-fix-publish-background-queue-parameters
- dev-fix-callback-process-parameters
- dev-fix-background-queue-publish-1
- dev-fix-background-queue-publish
This package is auto-updated.
Last update: 2024-09-05 03:04:21 UTC
README
允许在应用程序内进行邮件队列和延迟发送。
1.1 安装
composer
composer require adt/mail-queue
config.neon
extensions: adtMailQueue: ADT\MailQueue\DI\MailQueueExtension
1.1.1 使用默认队列实体
让Doctrine知道我们的实体
doctrine: metadata: ADT\MailQueue\Entity: %vendorDir%/adt/mail-queue/src/Entity
1.1.2 使用自定义队列实体
创建一个扩展我们抽象实体的自定义实体
namespace App\Model\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity */ class QueueEntity extends \ADT\MailQueue\Entity\AbstractMailQueueEntry { /** * @ORM\Column(type="text") */ protected $customProperty; }
让我们知道您的自定义实体
adtMailQueue: queueEntityClass: App\Model\Entity\QueueEntity
当入队邮件时填充您实体的自定义属性,您可以使用enqueue
的第二个参数
$this->mailQueueService->enqueue($mail, [ 'customProperty' => 'customValue' ]);
或者
$this->mailQueueService->enqueue($mail, function (QueueEntity $e) { $e->customProperty = 'customValue'; });
1.2.1 使用唯一的一个IMailer
adtMailQueue: mailer: @sparkPostApiMailerService
1.2.2 自定义邮件发送器
如果您需要根据您自定义队列实体中的信息来决定使用哪个邮件发送器,您可以实现ADT\MailQueue\Service\IMessenger
接口。此接口有一个send($entity)
方法,其中$entity
是您的自定义实体。
adtMailQueue: messenger: @queueMailerMessenger
1.3 迁移
清空您的temp/cache
目录。
生成迁移并迁移
php www/index.php migrations:diff php www/index.php migrations:migrate
1.4 处理入队消息
使用预定义的命令行工具
php www/index.php mail-queue:process
或者从DI容器获取ADT\MailQueue\Services\QueueService
并调用
$queueService->process()
1.5 发送错误处理器
如果您需要处理发送错误,您可以设置
adtMailQueue: sendErrorHandler: @ErrorHandlerClass::handlerMethod
处理器方法接收队列条目实体和发送时生成的异常。
1.6 队列清空事件
如果您需要在队列清空时收到通知,您可以设置
adtMailQueue: onQueueDrained: @EventHandlerClass::handlerMethod
如果可用,事件处理器接收OutputInterface
实例,否则接收NULL
。
2.1 配置
adtMailQueue: messenger: #or mailer queueEntityClass: #default Entity\MailQueueEntry::class, autowireMailer: false sendErrorHandler: null onQueueDrained: null lockTimeout: 600 limit: 1000 #how many emails send tempDir: %tempDir% backgroundQueueService: @ADT\BackgroundQueue\Service backgroundQueueCallbackName: mailSending