Giter Site home page Giter Site logo

stampie-bundle's Introduction

Stampie

CI

Stampie is a simple API Wrapper for different email providers such as Postmark and SendGrid.

It is very easy to use and to integrate into your application as demonstrated below with a SendGrid mailer.

Providers

<?php

// composer autoloading.
require 'vendor/autoload.php';

class Message extends \Stampie\Message
{
	public function getFrom() { return '[email protected]'; }
	public function getSubject() { return 'You are trying out Stampie'; }
	public function getText() { return 'So what do you think about it?'; }
}

$adapter = new Http\Adapter\Guzzle6\Client();
$mailer = new Stampie\Mailer\SendGrid($adapter, 'username:password');

// Throws an HttpException for error
// messages not recognized by SendGrid api or ApiException for known errors.
$mailer->send(new Message('[email protected]'));

This simple example shows a few different things about how Stampie works under the hood and is developed. Because others are so much better than us to do HTTP communication, Stampie uses the PSR-18 abstraction so you are free to choose between any library like Buzz or Guzzle. See the full list here: https://packagist.org/providers/psr/http-client-implementation

Every mailer takes a $serverToken as the second argument in their constructor. This is what is used for authentication. In the Postmark mailer this is a hash but in SendGrid it is a username:password pattern that is split into two pieces and send as arguments. A mailer is responsible for formatting the request needed for a given API.

A Message or MessageInterface is a simple storage class that holds information about the message sent to an API such as the email address this is from and who should receive it together with html and text bodies.

Last there is an interface for every type of class or abstract implementation that should be used when adding new Mailer's or Adapter's.

Installation

Stampie is not hard coupled to Guzzle or any other library that sends HTTP messages. It uses an abstraction called PSR-18. This will give you the flexibility to choose what PSR-7 implementation and HTTP client to use.

If you just want to get started quickly you should run the following command:

composer require stampie/stampie php-http/curl-client nyholm/psr7

Why requiring so many packages?

Stampie has a dependency on the virtual package psr/http-client-implementation which requires to you install an adapter, but we do not care which one. That is an implementation detail in your application. We also need a PSR-17 implementation.

You do not have to use the php-http/curl-client if you do not want to. You may use the php-http/guzzle6-adapter or any other library in this list.

Documentation

There is generated API documentation for all tags and released versions. Those can be found at stampie.github.io/Stampie/api/main/.

Extensions

  • Stampie Extra provides extensions to Stampie using the Symfony EventDispatcher component.

Framework integration

Stampie is itself completely decoupled and does not depend on any framework.

Integrations

Testing

Stampie is Continuous Integration tested with GitHub Actions and aims for a high coverage percentage.

Developing

As mentioned above if integrating new mailers or adapters please rely on the interfaces or abstract classes already in this package. Furthermore unit tests should be provided as well.

Feedback

This is a project created to test TDD along the way and maybe have some scars from that. But you are always welcome to send feedback or GitHub, Twitter, GitHub issue or Pull Request. Same goes if something is wrong or you have ideas for a better or smarter implementation.

stampie-bundle's People

Contributors

adrienbrault avatar fbourigault avatar henrikbjorn avatar kbond avatar lctrs avatar nyholm avatar pulse00 avatar stloyd avatar stof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

stampie-bundle's Issues

Please tag a new stable version of the bundle

A nasty bug exists in the 1.0.0 release. It has been fixed 2 days later but this fix is unreleased, which means that Composer users relying on stable versions won't get it. Please tag the 1.0.1 release

Cannot Use Mandrill mailer as a dependency because it is abstract

Hello everyone.

I am trying to implement the bundle to use Mandrill, but I am getting the following error

The definition "my_project.mailer.mailer" has a reference to an abstract definition "hb_stampie.mailer.mandrill". Abstract definitions cannot be the target of references.

I have a mailers.yml where I define my services:

parameters:
    my_project.mailer.sender_name: My Project
    my_project.mailer.deploy_instance: my_project
services:
    my_project.mailer.buzz.client:
        class: Buzz\Client\Curl
    my_project.mailer.buzz.factory:
        class: Buzz\Message\Factory\Factory
    buzz:
        class: Buzz\Browser
        arguments:
            - '@my_project.mailer.buzz.client'
            - '@my_project.mailer.buzz.factory'
    my_project.mailer.mailer:
        class: MyProject\MailerBundle\Mailer\Mailer
        arguments:
            - '@hb_stampie.mailer.mandrill'
            - '@templating'
            - %my_project.mailer.sender_name%
            - %my_project.mailer.deploy_instance%

My config.yml goes like this:

hb_stampie:
    adapter: buzz
    mailer: mandrill
    server_token: '%mandrill_api_key%'
    extra:
        delivery_address: '%mailer_delivery_address%'

And my service MyProject\MailerBundle\Mailer\Mailer goes like this (I put only the constructor function)

namespace MyProject\MailerBundle\Mailer;

use MyProject\WebBundle\Entity\Member;
use Stampie\Identity;
use Stampie\MailerInterface as StampieMailerInterface;

class Mailer implements MailerInterface
{
    private $mailer;
    private $twig;
    private $defaultSenderName;
    private $deployInstance;

    /**
     * @param StampieMailerInterface $mailer
     * @param \Twig_Environment        $twig
     * @param string                             $defaultSenderName
     * @param string                             $deployInstance
     */
    public function __construct(StampieMailerInterface $mailer, \Twig_Environment $twig, $defaultSenderName, $deployInstance)
    {
        $this->mailer = $mailer;
        $this->twig = $twig;
        $this->defaultSenderName = $defaultSenderName;
        $this->deployInstance = $deployInstance;
    }
}

My MailerInterface (implemented by MyProject\MailerBundle\Mailer\Mailer) is simply the following:

namespace MyProject\MailerBundle\Mailer;

interface MailerInterface
{
    /**
     * Sends a mail to the recipient(s) using the template.
     *
     * The template must define 3 blocks: subject, body_text and body_html.
     *
     * @param Message $message
     */
    public function send(Message $message);
}

Now if I look in the config.xml of the henrikbjorn bundle, I do have
<service id="hb_stampie.mailer.mandrill" class="%hb_stampie.mailer.mandrill.class%" abstract="true" />
which means that the hb_stampie.mailer.mandrill is an abstract class.

What am I missing in the configuration here? What should I do to be able to use Mandrill to send my mails?

SpoolMailer configuration

Hi,

what is the best way to configure SpoolMailer or is it not yet supported by the bundle?

Thanks for help!

Collecting Data not getting messages...

Hi guys!

While implementing Stampie for a given project, I faced the case where the DataCollector was not getting messages from the MessageLogger.

I overrided MessageLogger and StampieDataCollector in order to add a logger service.

The MessageLogger:preSend is well called, as far as I saw in my logs. When logging data from the DataCollector:collect, it seems there are no messages... Should I do something specific here?

Thanks for your time and help!

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.