starstruck0207/swiftmailerdbbundle

SwiftMailer 的数据库缓冲

安装数量: 1,362

依赖: 0

建议: 0

安全性: 0

星标: 0

关注者: 0

分支: 18

类型:symfony-bundle

1.1.2 2018-08-17 14:02 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: ~

贡献

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

如果您想贡献代码但不确定从哪里开始,问题列表 是一个很好的起点。如果您是首次贡献代码,GitHub 关于 分叉项目 的指南可能会有所帮助。

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