From 29c42ffa3712fb694e41da117103c099a1069a14 Mon Sep 17 00:00:00 2001 From: Vishal K <116670999+Vishalk91-4@users.noreply.github.com> Date: Sun, 8 Oct 2023 19:49:42 +0530 Subject: [PATCH 1/8] Created ElasticEmail.php --- .../Messaging/Adapters/Email/ElasticEmail.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/Email/ElasticEmail.php diff --git a/src/Utopia/Messaging/Adapters/Email/ElasticEmail.php b/src/Utopia/Messaging/Adapters/Email/ElasticEmail.php new file mode 100644 index 00000000..ebe2876d --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Email/ElasticEmail.php @@ -0,0 +1,71 @@ +request( + method: 'POST', + url: "https://$domain/v4/{$this->domain}/send", + headers: [ + 'Authorization: Basic '.base64_encode('api:'.$this->apiKey), + ], + body: http_build_query([ + 'apiKey' => $this->apiKey, + 'from' => $message->getFrom(), + 'fromName' => $message->getFromName(), + 'subject' => $message->getSubject(), + 'bodyHtml' => $message->isHtml() ? $message->getContent() : null, + 'bodyText' => $message->isHtml() ? null : $message->getContent(), + 'to' => implode(',', $message->getTo()), ]), + ); + + return $response; + } +} From 480894f74287b652f3bb44565f41abb694744a3a Mon Sep 17 00:00:00 2001 From: Vishal K <116670999+Vishalk91-4@users.noreply.github.com> Date: Sun, 8 Oct 2023 19:51:10 +0530 Subject: [PATCH 2/8] Created ElasticEmailTest.php --- tests/e2e/Email/ElasticEmailTest.php | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/e2e/Email/ElasticEmailTest.php diff --git a/tests/e2e/Email/ElasticEmailTest.php b/tests/e2e/Email/ElasticEmailTest.php new file mode 100644 index 00000000..c4c5f971 --- /dev/null +++ b/tests/e2e/Email/ElasticEmailTest.php @@ -0,0 +1,40 @@ +send($message)); + + $this->assertArrayHasKey('transactionId', $result); + $this->assertArrayHasKey('message', $result); + $this->assertTrue(str_contains(strtolower($result['message']), 'queued')); + } +} From ae3a8548de454fdb95d8ebe08299d611bf6d8910 Mon Sep 17 00:00:00 2001 From: Vishal K <116670999+Vishalk91-4@users.noreply.github.com> Date: Sun, 8 Oct 2023 19:52:34 +0530 Subject: [PATCH 3/8] Added environment for elastic email api key --- docker-compose.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..4be89e95 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: - MAILGUN_API_KEY - MAILGUN_DOMAIN - SENDGRID_API_KEY + - ElasticEmail_API_KEY - FCM_SERVER_KEY - FCM_SERVER_TO - TWILIO_ACCOUNT_SID @@ -44,4 +45,4 @@ services: request-catcher: image: appwrite/requestcatcher:1.0.0 ports: - - '10001:5000' \ No newline at end of file + - '10001:5000' From 2e8700d5393eed83be2153df2cd5a156e0e65dea Mon Sep 17 00:00:00 2001 From: Vishal K <116670999+Vishalk91-4@users.noreply.github.com> Date: Thu, 12 Oct 2023 23:12:02 +0530 Subject: [PATCH 4/8] Capitalized Elastic Email API KEY --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4be89e95..e4806687 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: - MAILGUN_API_KEY - MAILGUN_DOMAIN - SENDGRID_API_KEY - - ElasticEmail_API_KEY + - ELASTICEMAIL_API_KEY - FCM_SERVER_KEY - FCM_SERVER_TO - TWILIO_ACCOUNT_SID From f6484aa9b97ce2f6ae56eb3e584865c31265de1f Mon Sep 17 00:00:00 2001 From: Vishal K <116670999+Vishalk91-4@users.noreply.github.com> Date: Thu, 12 Oct 2023 23:13:29 +0530 Subject: [PATCH 5/8] Capitalized Elastic Email API KEY --- tests/e2e/Email/ElasticEmailTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Email/ElasticEmailTest.php b/tests/e2e/Email/ElasticEmailTest.php index c4c5f971..543922fe 100644 --- a/tests/e2e/Email/ElasticEmailTest.php +++ b/tests/e2e/Email/ElasticEmailTest.php @@ -12,7 +12,7 @@ class ElasticEmail extends Base */ public function testSendEmail() { - $key = getenv('ElasticEmail_API_KEY'); + $key = getenv('ELASTICEMAIL_API_KEY'); $sender = new ElasticEmail( apiKey: $key, From f2d8abd5799f43f565886211521735ed3c4dd14e Mon Sep 17 00:00:00 2001 From: Vishal K <116670999+Vishalk91-4@users.noreply.github.com> Date: Thu, 19 Oct 2023 14:16:56 +0530 Subject: [PATCH 6/8] Changed the Class Name --- tests/e2e/Email/ElasticEmailTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/Email/ElasticEmailTest.php b/tests/e2e/Email/ElasticEmailTest.php index 543922fe..76e79bef 100644 --- a/tests/e2e/Email/ElasticEmailTest.php +++ b/tests/e2e/Email/ElasticEmailTest.php @@ -5,14 +5,14 @@ use Utopia\Messaging\Adapters\Email\ElasticEmail; use Utopia\Messaging\Messages\Email; -class ElasticEmail extends Base +class ElasticEmailTest extends Base { /** * @throws \Exception */ public function testSendEmail() { - $key = getenv('ELASTICEMAIL_API_KEY'); + $key = getenv('ElasticEmail_API_KEY'); $sender = new ElasticEmail( apiKey: $key, From 5ff47d200330ee1fdb73177b005badb74d155841 Mon Sep 17 00:00:00 2001 From: Vishal K <116670999+Vishalk91-4@users.noreply.github.com> Date: Thu, 19 Oct 2023 20:45:13 +0530 Subject: [PATCH 7/8] Updated ElasticEmail.php --- src/Utopia/Messaging/Adapters/Email/ElasticEmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/Email/ElasticEmail.php b/src/Utopia/Messaging/Adapters/Email/ElasticEmail.php index ebe2876d..36f41701 100644 --- a/src/Utopia/Messaging/Adapters/Email/ElasticEmail.php +++ b/src/Utopia/Messaging/Adapters/Email/ElasticEmail.php @@ -41,7 +41,7 @@ public function getMaxMessagesPerRequest(): int /** * {@inheritdoc} * - * @param Email $message + * @param Email $message * @return string * * @throws \Exception From 5950dfbcb45f768c448748ec932155c66e3cc23d Mon Sep 17 00:00:00 2001 From: Vishal K <116670999+Vishalk91-4@users.noreply.github.com> Date: Thu, 19 Oct 2023 20:47:15 +0530 Subject: [PATCH 8/8] Updated ElasticEmailTest.php