Skip to content

Latest commit

 

History

History
94 lines (53 loc) · 2.06 KB

README.md

File metadata and controls

94 lines (53 loc) · 2.06 KB

TystrSendgridBundle

Build Status Test Coverage

A simple bundle for integrating the sendgrid php library into the Symfony2 framework.

Installation

Composer

Require the package with the following command:

$ composer.phar require tystr/sendgrid-bundle

Configuration

Add the following to your configuration file:

tystr_sendgrid:
    username: YOUR_SENDGRID_USERNAME
    password: YOUR_SENDGRID_PASSWORD

Register Bundle

In AppKernel.php, you need to register your bundle.

new Tystr\Bundle\SendgridBundle\TystrSendgridBundle(),

Usage

Retrieve the service like so:

$sendgrid = $this->get('tystr_sendgrid.sendgrid');

See the Sendgrid Documentation for more information.

WebHooks

The bundle supports sendgrid webhooks.

Add the bundles routing to your application

# in app/config/routing.yml

sendgrid_hooks:
    resource: "@TystrSendgridBundle/Resources/config/routing.xml"

Listen to any of the hook events

    <service id="acme_sendgrid_listener" class="Acme\Bundle\SendgridListener">
        <tag name="kernel.event_listener" event="sendgrid.bounce" method="onEmailBounce" />
    </service>
namespace Acme\Bundle;

use Tystr\Bundle\SendgridBundle\Event\WebHookEvent;

class SendgridListener
{
    public function onEmailBounce(WebHookEvent $event)
    {
        $this->logger->info('Address bounced: ' . $event-getEmail()->getOrElse('unknownEmail'));
    }
}

Register the webhook

In the sendgrid interface, register the URL http://yourApp.com/__tystr/sendgrid as the webhook.