2017 © Pedro Peláez
 

library mailjet-swiftmailer

A SwiftMailer transport implementation for Mailjet

image

mailjet/mailjet-swiftmailer

A SwiftMailer transport implementation for Mailjet

  • Monday, October 30, 2017
  • by Mailjet
  • Repository
  • 9 Watchers
  • 9 Stars
  • 44,051 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 10 Forks
  • 10 Open issues
  • 14 Versions
  • 41 % Grown

The README.md

MailjetSwiftMailer

Build Status Packagist Packagist GitHub license, (*1)

A SwiftMailer transport implementation for Mailjet ([NEW] we now support send API v3.1 ) Mailjet Send API v3.1 Compatible Mailjet send API V3 and V3.1, (*2)

If you found any problem, feel free to open an issue!, (*3)

TODO

  • Adding URL tags
  • Sandbox Mode
  • Improve unit-tests (lots of code duplications)

Installation

Require the package with composer, (*4)

composer require mailjet/mailjet-swiftmailer

Usage Example

$transport = new MailjetTransport($dispatchEvent, $apiKey, $apiSecret);
$transport->setClientOptions(['url' => "api.mailjet.com", 'version' => 'v3.1', 'call' => true]);


$transport->send($message);

(Send API v3 is selected by default), (*5)

Mailjet client custom configuration

You can pass an array in transport's constructor or use setClientOptions function:, (*6)

$clientOptions = ['url' => "api.mailjet.com", 'version' => 'v3.1', 'call' => false];
$transport = new MailjetTransport($dispatchEvent, $apiKey, $apiSecret, $clientOptions);


or

$transport->setClientOptions(['url' => "api.mailjet.com", 'version' => 'v3.1', 'call' => true]);

Properties of $options:, (*7)

  • url (Default: api.mailjet.com) : domain name of the API
  • version (Default: v3) : API version (only working for Mailjet API V3 +)
  • call (Default: true) : turns on(true) / off the call to the API
  • secured (Default: true) : turns on(true) / off the use of 'https'

Mailjet custom headers

It is possible to set specific Mailjet headers or custom user-defined headers, through SwiftMailer., (*8)

For example:, (*9)

$headers = $message->getHeaders();

$headers->addTextHeader('X-MJ-TemplateID', $templateId);
$headers->addTextHeader('X-MJ-TemplateLanguage', true);
$vars = array("myFirstVar" => "foo", "mySecondVar" => "bar");
$headers->addTextHeader('X-MJ-Vars', json_encode($vars));

Note: You need to json_encodeyour array of variables in order to be compatible with SMTP transport., (*10)

Mailjet bulk sending


$emails = ['f001@bar.com', 'f002@bar.com', 'f003@bar.com', 'f004@bar.com', 'f005@bar.com', 'f006@bar.com', ...] $messages = []; foreach ($emails as $email) { $message = new \Swift_Message('Test Subject', '

Foo bar, (*11)

', 'text/html'); $message ->addTo($email) ->addFrom('from@example.com', 'From Name') ->addReplyTo('reply-to@example.com', 'Reply To Name') ; array_push($messages, $message); } $transport = new MailjetTransport($dispatchEvent, $apiKey, $apiSecret); $result = $transport->bulkSend($messages);

Note: does not work with Spool (SwiftMailer removed bulkSend from its API)., (*12)

Integration in Symfony

If you want to use MailjetTransport in your Symfony project follow these small steps:, (*13)

  1. composer require mailjet/mailjet-swiftmailer
  2. Into your services.yml, register MailjetTransport:
swiftmailer.mailer.transport.mailjet:
    class: Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport
    arguments:
        - "@swiftmailer.transport.eventdispatcher.mailjet"
        - "%mailjet.api_key%"
        - "%mailjet.secret_key%"

Note: We set mailjet.api_key and mailjet.secret_key into parameters.yml, (*14)

  1. Finally, configure SwiftMailer in your config.yml:
# Swiftmailer Configuration
swiftmailer:
    transport: mailjet

Note: You can also inject your own Mailjet\Client:, (*15)

mailjet.transactionnal.client:
    class: "%mailjet.client.class%"
    arguments:
        - "%mailjet.api_key%"
        - "%mailjet.secret_key%"
        - %mailjet.transactionnal.call%
        - %mailjet.transactionnal.options%

swiftmailer.transport.eventdispatcher.mailjet:
    class: Swift_Events_SimpleEventDispatcher

swiftmailer.mailer.transport.mailjet:
    class: Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport
    arguments:
        - "@swiftmailer.transport.eventdispatcher.mailjet"
        - "%mailjet.api_key%"
        - "%mailjet.secret_key%"
        - %mailjet.transactionnal.call%
        - %mailjet.transactionnal.options%
    calls:
        - method: setExternalMailjetClient
          arguments:
              - '@mailjet.transactionnal.client'

Mailjet references

Execute Tests

vendor/bin/phpunit -c .

Contributing

If you want to contribute to this project, look at over here, (*16)

The Versions

30/10 2017

dev-upgradeToSwiftmailer6

dev-upgradeToSwiftmailer6 https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

27/10 2017

dev-master

9999999-dev https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

27/10 2017

1.0.6

1.0.6.0 https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

26/10 2017

dev-headers-variables-json

dev-headers-variables-json https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

31/07 2017

1.0.5

1.0.5.0 https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

17/07 2017

1.0.4

1.0.4.0 https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

17/07 2017

dev-handle_null_values

dev-handle_null_values https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

27/06 2017

1.0.3

1.0.3.0 https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

27/06 2017

dev-support_v3_and_v3.1

dev-support_v3_and_v3.1 https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

20/06 2017

1.0.2

1.0.2.0 https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

16/06 2017

1.0.1

1.0.1.0 https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

16/06 2017

dev-sendAPI3.1

dev-sendAPI3.1 https://github.com/mailjet/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

13/06 2017

1.0.0

1.0.0.0 https://github.com/welpdev/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet

07/06 2017

1.0-beta.2

1.0.0.0-beta2 https://github.com/welpdev/MailjetSwiftMailer

A SwiftMailer transport implementation for Mailjet

  Sources   Download

MIT

The Requires

 

The Development Requires

swiftmailer mailjet