From 0eac957a3f33b25e084507362f7285237bb959a1 Mon Sep 17 00:00:00 2001 From: Chandram-Dutta Date: Mon, 2 Oct 2023 15:04:48 +0530 Subject: [PATCH 1/2] Added Mailjet Mailjet adapter --- composer.lock | 4 +- .../Messaging/Adapters/Email/Mailjet.php | 85 +++++++++++++++++++ tests/e2e/Email/MailjetTest.php | 39 +++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/Utopia/Messaging/Adapters/Email/Mailjet.php create mode 100644 tests/e2e/Email/MailjetTest.php diff --git a/composer.lock b/composer.lock index 9f6b978b..599c4a03 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5ecbd865cbd7f14e7819fb79643573be", + "content-hash": "fb08c6484d53b5c0c2498e3fa9439fe0", "packages": [], "packages-dev": [ { @@ -1898,5 +1898,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Utopia/Messaging/Adapters/Email/Mailjet.php b/src/Utopia/Messaging/Adapters/Email/Mailjet.php new file mode 100644 index 00000000..cab56c2e --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Email/Mailjet.php @@ -0,0 +1,85 @@ +getTo() as $emails) { + foreach ($emails as $email) { + $toEmail[] = [ + "Email" => $email, + "Name" => $email + ]; + } + } + $apiKey = $this->apiKey; + $apiSecret = $this->apiSecret; + + $body = [ + 'Messages' => [ + [ + 'From' => [ + 'Email' => $message->getFrom(), + 'Name' => $message->getFrom() + ], + 'To' => $toEmail, + 'Subject' => $message->getSubject(), + 'TextPart' => $message->isHtml() ? null : $message->getContent(), + 'HTMLPart' => $message->isHtml() ? $message->getContent() : null + ] + ] + ]; + + return $this->request( + method: 'POST', + url: 'https://api.mailjet.com/v3.1/send', + headers: [ + 'Content-Type: application/json', + 'Authorization: Basic ' . base64_encode("$apiKey:$apiSecret") + ], + body: \json_encode($body) + ); + } +} diff --git a/tests/e2e/Email/MailjetTest.php b/tests/e2e/Email/MailjetTest.php new file mode 100644 index 00000000..c8c19747 --- /dev/null +++ b/tests/e2e/Email/MailjetTest.php @@ -0,0 +1,39 @@ +send($message)); + + $this->assertEquals('success', $result['Messages'][0]->Status); + } +} From 4c1cd2de0eced819a9e525592beba2c1376ddc5c Mon Sep 17 00:00:00 2001 From: Chandram-Dutta Date: Mon, 2 Oct 2023 15:11:56 +0530 Subject: [PATCH 2/2] fix: updated getMaxMessagesPerRequest --- src/Utopia/Messaging/Adapters/Email/Mailjet.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/Email/Mailjet.php b/src/Utopia/Messaging/Adapters/Email/Mailjet.php index cab56c2e..82094b5f 100644 --- a/src/Utopia/Messaging/Adapters/Email/Mailjet.php +++ b/src/Utopia/Messaging/Adapters/Email/Mailjet.php @@ -34,8 +34,7 @@ public function getName(): string */ public function getMaxMessagesPerRequest(): int { - //TODO - Check if this is correct - return 1000; + return 50; } /**