8000 feature #58698 [Mailer] Add AhaSend Bridge (farhadhf) · symfony/symfony@b4f121a · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b4f121a

Browse files
committed
feature #58698 [Mailer] Add AhaSend Bridge (farhadhf)
This PR was squashed before being merged into the 7.3 branch. Discussion ---------- [Mailer] Add AhaSend Bridge | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | | License | MIT | Doc PR | symfony/symfony-docs#20361 | Recipe PR | symfony/recipes#1350 This PR adds support for a new mail bridge for the [AhaSend](https://ahasend.com) email service. It includes support for SMTP and API transports (along with support for attachments for the API transport), and both delivery and engagement webhooks. Commits ------- 3dfad14 [Mailer] Add AhaSend Bridge
2 parents f86c095 + 3dfad14 commit b4f121a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1352
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,7 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
27452745
}
27462746

27472747
$classToServices = [
2748+
MailerBridge\AhaSend\Transport\AhaSendTransportFactory::class => 'mailer.transport_factory.ahasend',
27482749
MailerBridge\Azure\Transport\AzureTransportFactory::class => 'mailer.transport_factory.azure',
27492750
MailerBridge\Brevo\Transport\BrevoTransportFactory::class => 'mailer.transport_factory.brevo',
27502751
MailerBridge\Google\Transport\GmailTransportFactory::class => 'mailer.transport_factory.gmail',
@@ -2775,6 +2776,7 @@ private function registerMailerConfiguration(array $config, ContainerBuilder $co
27752776

27762777
if ($webhookEnabled) {
27772778
$webhookRequestParsers = [
2779+
MailerBridge\AhaSend\Webhook\AhaSendRequestParser::class => 'mailer.webhook.request_parser.ahasend',
27782780
MailerBridge\Brevo\Webhook\BrevoRequestParser::class => 'mailer.webhook.request_parser.brevo',
27792781
MailerBridge\MailerSend\Webhook\MailerSendRequestParser::class => 'mailer.webhook.request_parser.mailersend',
27802782
MailerBridge\Mailchimp\Webhook\MailchimpRequestParser::class => 'mailer.webhook.request_parser.mailchimp',

src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer_transports.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
use Symfony\Component\Mailer\Bridge\AhaSend\Transport\AhaSendTransportFactory;
1415
use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesTransportFactory;
1516
use Symfony\Component\Mailer\Bridge\Azure\Transport\AzureTransportFactory;
1617
use Symfony\Component\Mailer\Bridge\Brevo\Transport\BrevoTransportFactory;
@@ -47,6 +48,7 @@
4748
->tag('monolog.logger', ['channel' => 'mailer']);
4849

4950
$factories = [
51+
'ahasend' => AhaSendTransportFactory::class,
5052
'amazon' => SesTransportFactory::class,
5153
'azure' => AzureTransportFactory::class,
5254
'brevo' => BrevoTransportFactory::class,

src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer_webhook.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
use Symfony\Component\Mailer\Bridge\AhaSend\RemoteEvent\AhaSendPayloadConverter;
15+
use Symfony\Component\Mailer\Bridge\AhaSend\Webhook\AhaSendRequestParser;
1416
use Symfony\Component\Mailer\Bridge\Brevo\RemoteEvent\BrevoPayloadConverter;
1517
use Symfony\Component\Mailer\Bridge\Brevo\Webhook\BrevoRequestParser;
1618
use Symfony\Component\Mailer\Bridge\Mailchimp\RemoteEvent\MailchimpPayloadConverter;
@@ -86,6 +88,11 @@
8688
->args([service('mailer.payload_converter.sweego')])
8789
->alias(SweegoRequestParser::class, 'mailer.webhook.request_parser.sweego')
8890

91+
->set('mailer.payload_converter.ahasend', AhaSendPayloadConverter::class)
92+
->set('mailer.webhook.request_parser.ahasend', AhaSendRequestParser::class)
93+
->args([service('mailer.payload_converter.ahasend')])
94+
->alias(AhaSendRequestParser::class, 'mailer.webhook.request_parser.ahasend')
95+
8996
->set('mailer.payload_converter.mailchimp', MailchimpPayloadConverter::class)
9097
->set('mailer.webhook.request_parser.mailchimp', MailchimpRequestParser::class)
9198
->args([service('mailer.payload_converter.mailchimp')])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.git* export-ignore

src/Symfony/Component/Mailer/Bridge/AhaSend/.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Symfony/Component/Mailer/Bridge/AhaSend/.github/workflows/close-pull-request.yml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CHANGELOG
2+
=========
3+
4+
7.3
5+
---
6+
* Add the bridge
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 distribute F41A d with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Mailer\Bridge\AhaSend\Event;
13+
14+
class AhaSendDeliveryEvent
15+
{
16+
public function __construct(
17+
private readonly string $message,
18+
) {
19+
}
20+
21+
public function getMessage(): string
22+
{
23+
return $this->message;
24+
}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2024-present 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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
AhaSend Bridge
2+
==============
3+
4+
Provides AhaSend integration for Symfony Mailer.
5+
6+
Configuration example:
7+
8+
```env
9+
# SMTP
10+
MAILER_DSN=ahasend+smtp://USERNAME:PASSWORD@default
11+
12+
# API
13+
MAILER_DSN=ahasend+api://API_KEY@default
14+
```
15+
16+
where:
17+
- `USERNAME` is your AhaSend SMTP Credentials username
18+
- `PASSWORD` is your AhaSend SMTP Credentials password
19+
- `API_KEY` is your AhaSend API Key credential
20+
21+
Resources
22+
---------
23+
24+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
25+
* [Report issues](https://github.com/symfony/symfony/issues) and
26+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
27+
in the [main Symfony repository](https://github.com/symfony/symfony)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\AhaSend\RemoteEvent;
13+
14+
use Symfony\Component\RemoteEvent\Event\Mailer\AbstractMailerEvent;
15+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
16+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
17+
use Symfony\Component\RemoteEvent\Exception\ParseException;
18+
use Symfony\Component\RemoteEvent\PayloadConverterInterface;
19+
20+
final class AhaSendPayloadConverter implements PayloadConverterInterface
21+
{
22+
public function convert(array $payload): AbstractMailerEvent
23+
{
24+
if (\in_array($payload['type'], ['message.clicked', 'message.opened'])) {
25+
$name = match ($payload['type']) {
26+
'message.clicked' => MailerEngagementEvent::CLICK,
27+
'message.opened' => MailerEngagementEvent::OPEN,
28+
default => throw new ParseException(\sprintf('Unsupported event "%s".', $payload['type'])),
29+
};
30+
$event = new MailerEngagementEvent($name, $payload['data']['id'], $payload);
31+
} elseif (str_starts_with($payload['type'], 'message.')) {
32+
$name = match ($payload['type']) {
33+
'message.reception' => MailerDeliveryEvent::RECEIVED,
34+
'message.delivered' => MailerDeliveryEvent::DELIVERED,
35+
'message.transient_error' => MailerDeliveryEvent::DEFERRED,
36+
'message.failed', 'message.bounced' => MailerDeliveryEvent::BOUNCE,
37+
'message.suppressed' => MailerDeliveryEvent::DROPPED,
38+
default => throw new ParseException(\sprintf('Unsupported event "%s".', $payload['type'])),
39+
};
40+
$event = new MailerDeliveryEvent($name, $payload['data']['id'], $payload);
41+
} else {
42+
// suppressions and domain DNS problem webhooks. Ignore them for now.
43+
throw new ParseException(\sprintf('Unsupported event "%s".', $payload['type']));
44+
}
45+
46+
// AhaSend sends timestamps with 9 decimal places for nanosecond precision,
47+
// truncate to 6 decimal places for microseconds.
48+
$truncatedTimestamp = substr($payload['timestamp'], 0, 26).'Z';
49+
$date = \DateTimeImmutable::createFromFormat(\DateTimeImmutable::ATOM, $payload['timestamp']) ?: \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uT', $truncatedTimestamp);
50+
if (!$date) {
51+
throw new ParseException(\sprintf('Invalid date "%s".', $payload['timestamp']));
52+
}
53+
$event->setDate($date);
54+
$event->setRecipientEmail($payload['data']['recipient']);
55+
56+
return $event;
57+
}
58+
}

0 commit comments

Comments
 (0)
0