GithubHelp home page GithubHelp logo

ruudk / postmarkbundle Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 212 KB

This bundle lets you send messages via Postmark. It can offload the sending of messages to a Resque worker for speed and reliability.

License: MIT License

PHP 100.00%

postmarkbundle's Introduction

RuudkPostmarkBundle

Build Status

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: [email protected]   # 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('[email protected]');
$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('[email protected]');

$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

postmarkbundle's People

Contributors

ruudk avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.