2017 © Pedro Peláez
 

symfony-bundle swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

image

cspoo/swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

  • Tuesday, July 3, 2018
  • by cspoo
  • Repository
  • 12 Watchers
  • 75 Stars
  • 235,324 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 28 Forks
  • 10 Open issues
  • 13 Versions
  • 12 % Grown

The README.md

Swiftmailer Mailgun bundle

Latest Stable Version codecov.io Total Downloads Monthly Downloads Software License, (*1)

This bundle adds an extra transport to the swiftmailer service that uses the mailgun http interface for sending messages., (*2)

Installation

composer require cspoo/swiftmailer-mailgun-bundle php-http/guzzle5-adapter

Note: You can use any of these adapters, (*3)

Configuration

Symfony 3.4

Also add to your AppKernel:, (*4)

new cspoo\Swiftmailer\MailgunBundle\cspooSwiftmailerMailgunBundle(),

Configure your application with the credentials you find on the domain overview on the Mailgun.com dashboard., (*5)

``` yaml // app/config/config.yml: cspoo_swiftmailer_mailgun: key: "key-xxxxxxxxxx" domain: "mydomain.com" endpoint: "https://api.eu.mailgun.net" # Optional. Use this config for EU region. Defaults to "https://api.mailgun.net" http_client: "httplug.client" # Optional. Defaults to null and uses discovery to find client., (*6)

Swiftmailer Configuration

swiftmailer: transport: "mailgun" spool: { type: memory } # This will start sending emails on kernel.terminate event, (*7)

Note that the swiftmailer configuration is the same as the standard one - you just 
change the mailer_transport parameter.

### Symfony 4.1

Add your Mailgun credentials 
```bash
# both .env and .env.dist files
MAILGUN_DOMAIN=<your domain>
MAILGUN_API_KEY=<your key>
MAILGUN_SENDER=<your sender>

Adding to you bundle, (*8)

// config/bundles.php
return [
    ...
    cspoo\Swiftmailer\MailgunBundle\cspooSwiftmailerMailgunBundle::class => ['all' => true],
    ];

Configure your Mailgun credentials:, (*9)

// config/packages/mailgun.yaml
cspoo_swiftmailer_mailgun:
    key: '%env(MAILGUN_API_KEY)%'
    domain: "%env(MAILGUN_DOMAIN)%"

services:
    Mailgun\Mailgun:
        class: Mailgun\Mailgun
        factory: ['Mailgun\Mailgun', create]
        arguments: ['%env(MAILGUN_API_KEY)%']

Finally, add the following line on swiftmailer config:, (*10)

// config/packages/swiftmailer.yaml
swiftmailer:
    # url: '%env(MAILER_URL)%'
    transport: 'mailgun'
    spool: { type: 'memory' }

Note: Not sure if url line should be commented., (*11)

Usage

First craft a message:, (*12)

$message = \Swift_Message::newInstance()
        ->setSubject('Hello Email')
        ->setFrom('send@example.com')
        ->setTo('recipient@example.com')
        ->setBody(
            $this->renderView(
                'HelloBundle:Hello:email.txt.twig',
                array('name' => $name)
            )
        )
    ;

Then send it as you normally would with the mailer service. Your configuration ensures that you will be using the Mailgun transport., (*13)

$this->container->get('mailer')->send($message);

You can also test through terminal using:, (*14)

bin/console swiftmailer:email:send --from=<from email> --to=<to email> --subject="Foo" --body="Bar"

Choose HTTP client

Mailgun 2.0 is no longer coupled to Guzzle5. Thanks to Httplug you can now use any library to transport HTTP messages. You can rely on discovery to automatically find an installed client or you can use HttplugBundle and provide a client service name to the mailgun configuration., (*15)

yaml // app/config/config.yml: cspoo_swiftmailer_mailgun: http_client: 'httplug.client', (*16)

The Versions

10/01 2016

0.2.1

0.2.1.0 https://github.com/tehplague/swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

  Sources   Download

GPL-2.0+

The Requires

 

swiftmailer mailgun e-mail

23/10 2015

0.2.0

0.2.0.0 https://github.com/tehplague/swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

  Sources   Download

GPL

The Requires

 

swiftmailer mailgun e-mail

01/06 2015

0.1.2

0.1.2.0 https://github.com/tehplague/swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

  Sources   Download

GPL

The Requires

 

swiftmailer mailgun e-mail

20/04 2015

0.1.1

0.1.1.0 https://github.com/tehplague/swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

  Sources   Download

GPL

The Requires

 

swiftmailer mailgun e-mail

28/08 2014

0.1.0

0.1.0.0 https://github.com/tehplague/swiftmailer-mailgun-bundle

Swiftmailer Mailgun bundle

  Sources   Download

GPL

The Requires

 

swiftmailer mailgun e-mail