ruudk / postmark-bundle
This bundle lets you send messages via Postmark. It can offload the sending of messages to a Resque worker for speed and reliability.
Installs: 48
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
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
This bundle lets you send messages via Postmark. It can offload the sending of messages to a Resque worker for speed and reliability.
Installation
Step1: Require the package with Composer
php composer.phar require ruudk/postmark-bundle
Step2: Enable the bundles
Enable the bundles in the kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new BCC\ResqueBundle\BCCResqueBundle(), new Ruudk\PostmarkBundle\RuudkPostmarkBundle(), ); }
Step3: Configure
Configure the bundle.
# app/config/config_prod.yml ruudk_postmark: token: API KEY
Optionally, you can specify extra options
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
If you want to configure the BCCResqueBundle, check the docs.
Congratulations! You're ready.
Usage
Composing messages
/** * @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');
Sending messages
If you want to send the message directly:
$postmark->send($message);
To send the message to a Resque worker, add an extra delayed()
method:
$postmark->delayed()->send($message);
Batches
To send multiple messages in a batch (one API call):
$postmark->enqueue($message1); $postmark->enqueue($anotherMessage); $postmark->send();
Twig templates
This bundle supports Twig so that you can send a new message using a Twig template as a base.
Create a Twig template with a couple of blocks. It's not necessary to have them all.
{# 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 %}
And compose the message:
$message = $postmark->compose('AppBundle:Mail:email.html.twig', array( 'name' => 'Ruud' )); $message->addTo('test@gmail.com'); $postmark->send($message);
Resque
If you want to use a Resque worker to send the messages you'll have to start the worker first:
php app/console bcc:resque:worker-start -f postmark
Now when you send a message with the delayed()
method the worker will pick it up and send it.
Author
Ruud Kamphuis