ruudk / postmark-bundle
此包已被弃用,且不再维护。未建议替代包。
此包允许您通过 Postmark 发送消息。它可以通过将消息发送任务分配给 Resque 工作进程来提高速度和可靠性。
0.1.3
2013-05-14 10:16 UTC
Requires
- php: >=5.3.2
- bcc/resque-bundle: ~1.1
- kriswallsmith/buzz: ~0.9
- symfony/symfony: >=2.1,<2.3-dev
Requires (Dev)
This package is auto-updated.
Last update: 2022-02-01 12:24:15 UTC
README
此包允许您通过 Postmark 发送消息。它可以将消息发送任务分配给 Resque 工作进程,以提高速度和可靠性。
安装
步骤1:使用 Composer 需求包
php composer.phar require ruudk/postmark-bundle
步骤2:启用包
在内核中启用包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new BCC\ResqueBundle\BCCResqueBundle(), new Ruudk\PostmarkBundle\RuudkPostmarkBundle(), ); }
步骤3:配置
配置包。
# app/config/config_prod.yml ruudk_postmark: token: API KEY
可选,您可以指定额外选项
ruudk_postmark: delayed: true # Offload everything to a Resque worker by default disable_delivery: false # Set true for test environment from: email: info@my-app.com # Default from email name: My App, Inc # Default from name resque: queue: my-queue-name # Resque queue name to use, default is 'postmark' curl: timeout: 10 # Default Buzz\Curl timeout is 5 connect_timeout: 2
如果您想配置 BCCResqueBundle,请查看文档。
恭喜!您已准备就绪。
使用
编写消息
/** * @var \Ruudk\PostmarkBundle\Postmark\Postmark $postmark */ $postmark = $this->container->get('ruudk_postmark.postmark'); $message = $postmark->compose(); $message->addTo('test@gmail.com'); $message->setSubject('Subject'); $message->setTextBody('Body'); $message->setHtmlBody('Body');
发送消息
如果您想直接发送消息
$postmark->send($message);
要发送消息到 Resque 工作进程,请添加额外的 delayed()
方法
$postmark->delayed()->send($message);
批量处理
要批量发送多条消息(一个 API 调用)
$postmark->enqueue($message1); $postmark->enqueue($anotherMessage); $postmark->send();
Twig 模板
此包支持 Twig,因此您可以使用 Twig 模板作为基础来发送新消息。
创建一个带有几个块的 Twig 模板。不一定需要所有块。
{# AppBundle:Mail:email.html.twig #} {% block subject %} The subject of the message {% endblock %} {% block text %} Hi {{ name }}, How are you today? {% endblock text %} {% block html %} <p>Hi <strong>{{ name }}</strong>,</p> <p>How are you today?</p> {% endblock html %}
然后编写消息
$message = $postmark->compose('AppBundle:Mail:email.html.twig', array( 'name' => 'Ruud' )); $message->addTo('test@gmail.com'); $postmark->send($message);
Resque
如果您想使用 Resque 工作进程发送消息,您必须首先启动工作进程: php app/console bcc:resque:worker-start -f postmark
现在,当您使用 delayed()
方法发送消息时,工作进程将获取它并发送。
作者
Ruud Kamphuis