Skip to content

Commit cc30b0c

Browse files
committed
✨ [Mailer] Add Mailjet bridge
1 parent f2f82d1 commit cc30b0c

File tree

11 files changed

+265
-0
lines changed

11 files changed

+265
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
4.4.0
5+
-----
6+
7+
* Added the bridge
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2019-2020 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Mailjet Bridge
2+
===============
3+
4+
Provides Mailjet integration for Symfony Mailer.
5+
6+
Resources
7+
---------
8+
9+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
10+
* [Report issues](https://github.com/symfony/symfony/issues) and
11+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
12+
in the [main Symfony repository](https://github.com/symfony/symfony)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Bridge\Mailjet\Tests\Transport;
13+
14+
use Symfony\Component\Mailer\Bridge\Mailjet\Transport\MailjetSmtpTransport;
15+
use Symfony\Component\Mailer\Bridge\Mailjet\Transport\MailjetTransportFactory;
16+
use Symfony\Component\Mailer\Test\TransportFactoryTestCase;
17+
use Symfony\Component\Mailer\Transport\Dsn;
18+
use Symfony\Component\Mailer\Transport\TransportFactoryInterface;
19+
20+
class MailjetTransportFactoryTest extends TransportFactoryTestCase
21+
{
22+
public function getFactory(): TransportFactoryInterface
23+
{
24+
return new MailjetTransportFactory($this->getDispatcher(), $this->getClient(), $this->getLogger());
25+
}
26+
27+
public function supportsProvider(): iterable
28+
{
29+
yield [
30+
new Dsn('mailjet', 'default'),
31+
true,
32+
];
33+
34+
yield [
35+
new Dsn('mailjet+smtp', 'default'),
36+
true,
37+
];
38+
39+
yield [
40+
new Dsn('mailjet+smtps', 'default'),
41+
true,
42+
];
43+
44+
yield [
45+
new Dsn('mailjet+smtp', 'example.com'),
46+
true,
47+
];
48+
}
49+
50+
public function createProvider(): iterable
51+
{
52+
$dispatcher = $this->getDispatcher();
53+
$logger = $this->getLogger();
54+
55+
yield [
56+
new Dsn('mailjet', 'default', self::USER, self::PASSWORD),
57+
new MailjetSmtpTransport(self::USER, self::PASSWORD, $dispatcher, $logger),
58+
];
59+
60+
yield [
61+
new Dsn('mailjet+smtp', 'default', self::USER, self::PASSWORD),
62+
new MailjetSmtpTransport(self::USER, self::PASSWORD, $dispatcher, $logger),
63+
];
64+
65+
yield [
66+
new Dsn('mailjet+smtps', 'default', self::USER, self::PASSWORD),
67+
new MailjetSmtpTransport(self::USER, self::PASSWORD, $dispatcher, $logger),
68+
];
69+
}
70+
71+
public function unsupportedSchemeProvider(): iterable
72+
{
73+
yield [
74+
new Dsn('mailjet+foo', 'mailjet', self::USER, self::PASSWORD),
75+
'The "mailjet+foo" scheme is not supported; supported schemes for mailer "mailjet" are: "mailjet", "mailjet+smtp", "mailjet+smtps".',
76+
];
77+
}
78+
79+
public function incompleteDsnProvider(): iterable
80+
{
81+
yield [new Dsn('mailjet+smtp', 'default')];
82+
}
83+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Bridge\Mailjet\Transport;
13+
14+
15+
use Psr\Log\LoggerInterface;
16+
use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
17+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
18+
19+
class MailjetSmtpTransport extends EsmtpTransport
20+
{
21+
public function __construct(string $username, string $password, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
22+
{
23+
parent::__construct('in-v3.mailjet.com', 465, true, $dispatcher, $logger);
24+
25+
$this->setUsername($username);
26+
$this->setPassword($password);
27+
}
28+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
13+
namespace Symfony\Component\Mailer\Bridge\Mailjet\Transport;
14+
15+
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;
16+
use Symfony\Component\Mailer\Transport\AbstractTransportFactory;
17+
use Symfony\Component\Mailer\Transport\Dsn;
18+
use Symfony\Component\Mailer\Transport\TransportInterface;
19+
20+
class MailjetTransportFactory extends AbstractTransportFactory
21+
{
22+
public function create(Dsn $dsn): TransportInterface
23+
{
24+
$scheme = $dsn->getScheme();
25+
$user = $this->getUser($dsn);
26+
$password = $this->getPassword($dsn);
27+
28+
if ('mailjet+smtp' === $scheme || 'mailjet+smtps' === $scheme || 'mailjet' === $scheme) {
29+
return new MailjetSmtpTransport($user, $password, $this->dispatcher, $this->logger);
30+
}
31+
32+
throw new UnsupportedSchemeException($dsn, 'mailjet', $this->getSupportedSchemes());
33+
}
34+
35+
protected function getSupportedSchemes(): array
36+
{
37+
return ['mailjet', 'mailjet+smtp', 'mailjet+smtps'];
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "symfony/mailjet-mailer",
3+
"type": "symfony-bridge",
4+
"description": "Symfony Mailjet Mailer Bridge",
5+
"keywords": [],
6+
"homepage": "https://symfony.com",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Fabien Potencier",
11+
"email": "fabien@symfony.com"
12+
},
13+
{
14+
"name": "Symfony Community",
15+
"homepage": "https://symfony.com/contributors"
16+
}
17+
],
18+
"require": {
19+
"php": "^7.2.5",
20+
"symfony/mailer": "^4.4|^5.0"
21+
},
22+
"require-dev": {
23+
"symfony/http-client": "^4.4|^5.0"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"Symfony\\Component\\Mailer\\Bridge\\Mailjet\\": ""
28+
},
29+
"exclude-from-classmap": [
30+
"/Tests/"
31+
]
32+
},
33+
"minimum-stability": "dev",
34+
"extra": {
35+
"branch-alias": {
36+
"dev-master": "5.1-dev"
37+
}
38+
}
39+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
failOnRisky="true"
9+
failOnWarning="true"
10+
>
11+
<php>
12+
<ini name="error_reporting" value="-1"/>
13+
</php>
14+
15+
<testsuites>
16+
<testsuite name="Symfony Mailjet Mailer Test Suite">
17+
<directory>./Tests/</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<filter>
22+
<whitelist>
23+
<directory>./</directory>
24+
<exclude>
25+
<directory>./Resources</directory>
26+
<directory>./Tests</directory>
27+
<directory>./vendor</directory>
28+
</exclude>
29+
</whitelist>
30+
</filter>
31+
</phpunit>

src/Symfony/Component/Mailer/Exception/UnsupportedSchemeException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class UnsupportedSchemeException extends LogicException
4444
'class' => Bridge\Mailchimp\Transport\MandrillTransportFactory::class,
4545
'package' => 'symfony/mailchimp-mailer',
4646
],
47+
'mailjet' => [
48+
'class' => Bridge\Mailjet\Transport\MailjetTransportFactory::class,
49+
'package' => 'symfony/mailjet-mailer',
50+
],
4751
];
4852

4953
public function __construct(Dsn $dsn, string $name = null, array $supported = [])

src/Symfony/Component/Mailer/Transport.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Mailer\Bridge\Google\Transport\GmailTransportFactory;
1717
use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillTransportFactory;
1818
use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory;
19+
use Symfony\Component\Mailer\Bridge\Mailjet\Transport\MailjetTransportFactory;
1920
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
2021
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridTransportFactory;
2122
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
@@ -45,6 +46,7 @@ class Transport
4546
MailgunTransportFactory::class,
4647
PostmarkTransportFactory::class,
4748
SendgridTransportFactory::class,
49+
MailjetTransportFactory::class,
4850
];
4951

5052
private $factories;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy