All Projects → mailjet → MailjetSwiftMailer

mailjet / MailjetSwiftMailer

Licence: MIT license
A SwiftMailer transport implementation for Mailjet

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to MailjetSwiftMailer

zx-ip-address
Deprecated
Stars: ✭ 96 (+269.23%)
Mutual labels:  packagist
yii2-fullcalendar-scheduler
Yii 2 component for easy fullcalendar scheduler integration
Stars: ✭ 24 (-7.69%)
Mutual labels:  packagist
private-packagist-api-client
Private Packagist API Client
Stars: ✭ 28 (+7.69%)
Mutual labels:  packagist
Container
🚀 PHP Service Container with fast and cachable dependency injection.
Stars: ✭ 28 (+7.69%)
Mutual labels:  packagist
packagist
🐳 Dockette out-of-box Packagist (Nginx / Solr 6 / PHP 7.1+FPM)
Stars: ✭ 32 (+23.08%)
Mutual labels:  packagist
laravel-task
A simple way to trigger tasks in a clean and simple way
Stars: ✭ 18 (-30.77%)
Mutual labels:  packagist
MailHookBundle
A bundle to catch API webhook from different mail service
Stars: ✭ 36 (+38.46%)
Mutual labels:  mailjet
composer-diff
Compares composer.lock changes and generates Markdown report so you can use it in PR description.
Stars: ✭ 51 (+96.15%)
Mutual labels:  packagist
composer-localdev-plugin
Composer Plugin for local development
Stars: ✭ 31 (+19.23%)
Mutual labels:  packagist
php-base-project
A Composer ready package to start a new PHP 7 project
Stars: ✭ 17 (-34.62%)
Mutual labels:  packagist
rippled-php
A PHP library for rippled (XRP Ledger) communication.
Stars: ✭ 33 (+26.92%)
Mutual labels:  packagist
generator-composer
🐘 Yeoman (http://yeoman.io) generator for a PHP Composer project
Stars: ✭ 16 (-38.46%)
Mutual labels:  packagist
upcloud-php-api
PHP client for UpCloud's API
Stars: ✭ 23 (-11.54%)
Mutual labels:  packagist
firebase-php
Firebase Realtime Database PHP Wrapper
Stars: ✭ 41 (+57.69%)
Mutual labels:  packagist
slim-mobile-detect
Implements Mobile-Detect lib for Response's write on Slim Framework App
Stars: ✭ 18 (-30.77%)
Mutual labels:  packagist
packagist-mirror-docker
🐋📦✂️📋📦 Docker image of packagist mirror
Stars: ✭ 28 (+7.69%)
Mutual labels:  packagist
laravel-stripe-connect
🦓 Stripe Connect binding for Laravel
Stars: ✭ 73 (+180.77%)
Mutual labels:  packagist
composer-velocita
Velocita - Composer plugin for transparent caching
Stars: ✭ 26 (+0%)
Mutual labels:  packagist
ip
Immutable value object for IPv4 and IPv6 addresses, including helper methods and Doctrine support.
Stars: ✭ 212 (+715.38%)
Mutual labels:  packagist
guzzle6-bundle
Integrates Guzzle 6 into your Symfony application
Stars: ✭ 11 (-57.69%)
Mutual labels:  packagist

MailjetSwiftMailer

Build Status Packagist Packagist GitHub license

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

If you found any problem, feel free to open an issue!

TODO

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

Installation

Require the package with composer

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)

Mailjet client custom configuration

You can pass an array in transport's constructor or use setClientOptions function:

$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:

  • 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.

For example:

$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.

Mailjet bulk sending

$emails = ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', ...]

$messages = [];
foreach ($emails as $email) {
    $message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
    $message
        ->addTo($email)
        ->addFrom('[email protected]', 'From Name')
        ->addReplyTo('[email protected]', '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).

Integration in Symfony

If you want to use MailjetTransport in your Symfony project follow these small steps:

  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

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

Note: You can also inject your own Mailjet\Client:

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].