Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
98 changed files
with
4,888 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<defaults public="false" /> | ||
|
||
<service id="mailer" class="Symfony\Component\Mailer\Mailer"> | ||
<argument type="service" id="mailer.transport" /> | ||
<argument type="service" id="message_bus" on-invalid="ignore" /> | ||
</service> | ||
<service id="Symfony\Component\Mailer\MailerInterface" alias="mailer" /> | ||
|
||
<service id="mailer.transport" class="Symfony\Component\Mailer\Transport\TransportInterface"> | ||
<factory class="Symfony\Component\Mailer\Transport" method="fromDsn" /> | ||
<argument></argument> <!-- env(MAILER_DSN) --> | ||
<argument type="service" id="event_dispatcher" /> | ||
<argument type="service" id="http_client" on-invalid="ignore" /> | ||
<argument type="service" id="logger" on-invalid="ignore" /> | ||
</service> | ||
<service id="Symfony\Component\Mailer\Transport\TransportInterface" alias="mailer.transport" /> | ||
|
||
<service id="mailer.messenger.message_handler" class="Symfony\Component\Mailer\Messenger\MessageHandler"> | ||
<argument type="service" id="mailer.transport" /> | ||
<tag name="messenger.message_handler" /> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<defaults public="false" /> | ||
|
||
<service id="twig.mailer.message_listener" class="Symfony\Component\Mailer\EventListener\MessageListener"> | ||
<argument /> | ||
<argument type="service" id="twig.mime_body_renderer" /> | ||
</service> | ||
|
||
<service id="twig.mime_body_renderer" class="Symfony\Bridge\Twig\Mime\BodyRenderer"> | ||
<argument type="service" id="twig" /> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CHANGELOG | ||
========= | ||
|
||
4.3.0 | ||
----- | ||
|
||
* added the bridge |
103 changes: 103 additions & 0 deletions
103
src/Symfony/Component/Mailer/Bridge/Amazon/Http/Api/SesTransport.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Bridge\Amazon\Http\Api; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Mailer\Exception\TransportException; | ||
use Symfony\Component\Mailer\SmtpEnvelope; | ||
use Symfony\Component\Mailer\Transport\Http\Api\AbstractApiTransport; | ||
use Symfony\Component\Mime\Email; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
/** | ||
* @experimental in 4.3 | ||
*/ | ||
class SesTransport extends AbstractApiTransport | ||
{ | ||
private const ENDPOINT = 'https://email.%region%.amazonaws.com'; | ||
|
||
private $accessKey; | ||
private $secretKey; | ||
private $region; | ||
|
||
/** | ||
* @param string $region Amazon SES region (currently one of us-east-1, us-west-2, or eu-west-1) | ||
*/ | ||
public function __construct(string $accessKey, string $secretKey, string $region = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null) | ||
{ | ||
$this->accessKey = $accessKey; | ||
$this->secretKey = $secretKey; | ||
$this->region = $region ?: 'eu-west-1'; | ||
|
||
parent::__construct($client, $dispatcher, $logger); | ||
} | ||
|
||
protected function doSendEmail(Email $email, SmtpEnvelope $envelope): void | ||
{ | ||
$date = gmdate('D, d M Y H:i:s e'); | ||
$auth = sprintf('AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HmacSHA256,Signature=%s', $this->accessKey, $this->getSignature($date)); | ||
|
||
$endpoint = str_replace('%region%', $this->region, self::ENDPOINT); | ||
$response = $this->client->request('POST', $endpoint, [ | ||
'headers' => [ | ||
'X-Amzn-Authorization' => $auth, | ||
'Date' => $date, | ||
'Content-Type' => 'application/x-www-form-urlencoded', | ||
], | ||
'body' => $this->getPayload($email, $envelope), | ||
]); | ||
|
||
if (200 !== $response->getStatusCode()) { | ||
$error = new \SimpleXMLElement($response->getContent(false)); | ||
|
||
throw new TransportException(sprintf('Unable to send an email: %s (code %s).', $error->Error->Message, $error->Error->Code)); | ||
} | ||
} | ||
|
||
private function getSignature(string $string): string | ||
{ | ||
return base64_encode(hash_hmac('sha256', $string, $this->secretKey, true)); | ||
} | ||
|
||
private function getPayload(Email $email, SmtpEnvelope $envelope): array | ||
{ | ||
if ($email->getAttachments()) { | ||
return [ | ||
'Action' => 'SendRawEmail', | ||
'RawMessage.Data' => \base64_encode($email->toString()), | ||
]; | ||
} | ||
|
||
$payload = [ | ||
'Action' => 'SendEmail', | ||
'Destination.ToAddresses.member' => $this->stringifyAddresses($this->getRecipients($email, $envelope)), | ||
'Message.Subject.Data' => $email->getSubject(), | ||
'Source' => $envelope->getSender()->toString(), | ||
]; | ||
|
||
if ($emails = $email->getCc()) { | ||
$payload['Destination.CcAddresses.member'] = $this->stringifyAddresses($emails); | ||
} | ||
if ($emails = $email->getBcc()) { | ||
$payload['Destination.BccAddresses.member'] = $this->stringifyAddresses($emails); | ||
} | ||
if ($email->getTextBody()) { | ||
$payload['Message.Body.Text.Data'] = $email->getTextBody(); | ||
} | ||
if ($email->getHtmlBody()) { | ||
$payload['Message.Body.Html.Data'] = $email->getHtmlBody(); | ||
} | ||
|
||
return $payload; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/Symfony/Component/Mailer/Bridge/Amazon/Http/SesTransport.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Mailer\Bridge\Amazon\Http; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\HttpClient\HttpClient; | ||
use Symfony\Component\Mailer\Exception\TransportException; | ||
use Symfony\Component\Mailer\SentMessage; | ||
use Symfony\Component\Mailer\Transport\AbstractTransport; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
/** | ||
* @experimental in 4.3 | ||
*/ | ||
class SesTransport extends AbstractTransport | ||
{ | ||
private const ENDPOINT = 'https://email.%region%.amazonaws.com'; | ||
|
||
private $client; | ||
private $accessKey; | ||
private $secretKey; | ||
private $region; | ||
|
||
/** | ||
* @param string $region Amazon SES region (currently one of us-east-1, us-west-2, or eu-west-1) | ||
*/ | ||
public function __construct(string $accessKey, string $secretKey, string $region = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null) | ||
{ | ||
$this->client = $client ?? HttpClient::create(); | ||
$this->accessKey = $accessKey; | ||
$this->secretKey = $secretKey; | ||
$this->region = $region ?: 'eu-west-1'; | ||
|
||
parent::__construct($dispatcher, $logger); | ||
} | ||
|
||
protected function doSend(SentMessage $message): void | ||
{ | ||
$date = gmdate('D, d M Y H:i:s e'); | ||
$auth = sprintf('AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HmacSHA256,Signature=%s', $this->accessKey, $this->getSignature($date)); | ||
|
||
$endpoint = str_replace('%region%', $this->region, self::ENDPOINT); | ||
$response = $this->client->request('POST', $endpoint, [ | ||
'headers' => [ | ||
'X-Amzn-Authorization' => $auth, | ||
'Date' => $date, | ||
], | ||
'body' => [ | ||
'Action' => 'SendRawEmail', | ||
'RawMessage.Data' => \base64_encode($message->toString()), | ||
], | ||
]); | ||
|
||
if (200 !== $response->getStatusCode()) { | ||
$error = new \SimpleXMLElement($response->getContent(false)); | ||
|
||
throw new TransportException(sprintf('Unable to send an email: %s (code %s).', $error->Error->Message, $error->Error->Code)); | ||
} | ||
} | ||
|
||
private function getSignature(string $string): string | ||
{ | ||
return base64_encode(hash_hmac('sha256', $string, $this->secretKey, true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2019 Fabien Potencier | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Amazon Mailer | ||
============= | ||
|
||
Provides Amazon SES integration for Symfony Mailer. | ||
|
||
Resources | ||
--------- | ||
|
||
* [Contributing](https://symfony.com/doc/current/contributing/index.html) | ||
* [Report issues](https://github.com/symfony/symfony/issues) and | ||
[send Pull Requests](https://github.com/symfony/symfony/pulls) | ||
in the [main Symfony repository](https://github.com/symfony/symfony) |
Oops, something went wrong.