8000 [Mailer] Add MailerSend bridge by doobas · Pull Request #49461 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] Add MailerSend bridge #49461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changes after review
  • Loading branch information
doobas committed Feb 22, 2023
commit b037aa40718378023f5a38aa6f8e86899fc87cb0
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ CHANGELOG
6.3
---

* Add the bridge
* Add the bridge
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/Bridge/MailerSend/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2019-present Fabien Potencier
Copyright (c) 2023-present 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
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mailer/Bridge/MailerSend/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MailerSend Bridge
===============
=================

Provides MailerSend integration for Symfony Mailer.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class MailerSendTransportFactoryTest extends TransportFactoryTestCase
{
public static function getFactory(): TransportFactoryInterface
public function getFactory(): TransportFactoryInterface
{
return new MailerSendTransportFactory(null, new MockHttpClient(), new NullLogger());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\Exception\JsonException;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\Exception\HttpTransportException;
use Symfony\Component\Mailer\SentMessage;
Expand All @@ -30,7 +31,7 @@ final class MailerSendApiTransport extends AbstractApiTransport
{
private string $key;

public function __construct(string $key, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
public function __construct(#[\SensitiveParameter] string $key, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
{
$this->key = $key;

Expand All @@ -53,17 +54,17 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e

try {
$statusCode = $response->getStatusCode();
$result = $response->getContent(false);
$content = $response->getContent(false);
$headers = $response->getHeaders(false);
} catch (TransportExceptionInterface $e) {
throw new HttpTransportException('Could not reach the remote MailerSend server.', $response, 0, $e);
}

if (!empty($result)) {
if ('' !== $content) {
try {
$result = json_decode($result, true, 512, \JSON_THROW_ON_ERROR);
$result = json_decode($content, true, 512, \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new HttpTransportException(sprintf('Unable to send an email: "%s" (code %d).', $result, $statusCode), $response, 0, $e);
throw new HttpTransportException(sprintf('Unable to send an email: "%s" (code %d).', $content, $statusCode), $response, 0, $e);
}
}

Expand Down Expand Up @@ -125,7 +126,7 @@ private function getPayload(Email $email, Envelope $envelope): array
/**
* @param Address[] $addresses
*/
protected function prepareAddresses(array $addresses): array
private function prepareAddresses(array $addresses): array
{
$recipients = [];

Expand Down Expand Up @@ -163,7 +164,7 @@ private function prepareAttachments(Email $email): array
return $attachments;
}

private function getEndpoint(): ?string
private function getEndpoint(): string
{
return ($this->host ?: 'api.mailersend.com').($this->port ? ':'.$this->port : '');
}
Expand Down
0