vkalmuks/swiftmailerdbbundle

SwiftMailer 的数据库队列

安装: 2

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 18

类型:symfony-bundle

1.1.2 2018-08-17 14:02 UTC

This package is auto-updated.

Last update: 2024-09-29 06:14:28 UTC


README

Latest Stable Version Total Downloads Monthly Downloads License

SwiftMailer

此捆绑包简化了使用数据库队列将消息传递给 SwiftMailer 和 Symfony2 的过程。

目前,它只与 Doctrine EntityManager 以及由此管理的实体一起工作。

安装和配置

1. 通过 Composer 安装

$ composer require "whiteoctober/swiftmailerdbbundle:^1.0"

2. 将捆绑包添加到应用程序的内核

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new WhiteOctober\SwiftMailerDBBundle\WhiteOctoberSwiftMailerDBBundle(),
        // ...
    );
}

3. 在 config.yml 中配置 white_october_swift_mailer_db

white_october_swift_mailer_db:
    entity_class: AppBundle\Entity\Email

下面将详细介绍如何构建此实体。

4. 告知 SwiftMailer 使用数据库队列

swiftmailer:
    spool:
        type: db

捆绑包的安装和配置就完成了。

邮件实体

您需要创建一个可以持久化且扩展捆绑包中 EmailInterface 接口的实体。目前,捆绑包期望您的实体中存在一个名为 'status' 的属性,因为该字段将被查询。

一旦您的实体设置完成,就像上面详细描述的那样,在您的 config.yml 配置中使用全命名空间路径。

可选:将发送的邮件保留在数据库中

默认情况下,成功发送的邮件将从数据库中删除。您可以通过配置捆绑包来在您的 config.yml 中保留这些邮件。

white_october_swift_mailer_db:
    keep_sent_messages: true

可选:为电子邮件使用单独的实体管理器

当使用配置的数据库队列发送邮件时,默认实体管理器会调用 $em->flush。这可能会导致副作用,因此为了只刷新 Email 实体,请将其放入单独的捆绑包中,并为该捆绑包配置单独的实体管理器。例如:

white_october_swift_mailer_db:
    entity_class: MailBundle\Entity\Email

doctrine:
    orm:
        entity_managers:
            default:
                connection: default
                auto_mapping: true
            mail:
                connection: default
                mappings:
                    MailBundle: ~

贡献

我们欢迎对此项目的贡献,包括拉取请求和问题(以及现有问题的讨论)。

如果您想贡献代码但不确定从哪里开始,问题列表 issues list 是一个好的起点。如果您是首次贡献代码,您可能会发现 Github 的指南 forking projects 有所帮助。

所有贡献者(无论是否贡献代码、参与问题讨论或以其他方式参与)都必须遵守我们的 行为准则