From 012ce9080ed7c231ba943fe1e0a78970785bf4e3 Mon Sep 17 00:00:00 2001 From: Kartik Jolapara Date: Thu, 12 Oct 2023 00:53:21 +0530 Subject: [PATCH 1/3] feat: add Netcore Email Adapter Signed-off-by: Kartik Jolapara --- .../Messaging/Adapters/Email/Netcore.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/Email/Netcore.php diff --git a/src/Utopia/Messaging/Adapters/Email/Netcore.php b/src/Utopia/Messaging/Adapters/Email/Netcore.php new file mode 100644 index 00000000..5a934e62 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Email/Netcore.php @@ -0,0 +1,75 @@ +isEU ? $euDomain : $usDomain; + + $body = [ + 'to' => \implode(',', $message->getTo()), + 'from' => $message->getFrom(), + 'subject' => $message->getSubject(), + 'content' => [ + 'type' => $message->isHtml() ? 'html' : 'amp', + 'value' => $message->getContent(), + ], + ]; + + $response = $this->request( + method: 'POST', + url: "https://$domain/v5.1/mail/send", + headers: [ + 'apiKey: '.base64_encode('api:'.$this->apiKey), + 'Accept: application/json', + 'Content-Type: application/json', + ], + body: \json_encode($body) + ); + + return $response; + } +} From 3551534954e138bdeb79d087e681fa54a08ea568 Mon Sep 17 00:00:00 2001 From: Kartik Jolapara Date: Thu, 12 Oct 2023 01:01:00 +0530 Subject: [PATCH 2/3] feat: add Netcore Email tests Signed-off-by: Kartik Jolapara --- tests/e2e/Email/NetcoreTest.php | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/e2e/Email/NetcoreTest.php diff --git a/tests/e2e/Email/NetcoreTest.php b/tests/e2e/Email/NetcoreTest.php new file mode 100644 index 00000000..34ce9e14 --- /dev/null +++ b/tests/e2e/Email/NetcoreTest.php @@ -0,0 +1,41 @@ +markTestSkipped('Netcore credentials not set.'); + + $key = getenv('NETCORE_API_KEY'); + $sender = new Netcore( + apiKey: $key, + isEU: false + ); + + $to = getenv('TEST_EMAIL'); + $subject = 'Test Subject'; + $content = 'Test Content'; + $from = getenv('TEST_FROM_EMAIL'); + + $message = new Email( + to: [$to], + from: $from, + subject: $subject, + content: $content, + ); + + $result = (array) \json_decode($sender->send($message)); + + $this->assertArrayHasKey('data', $result); + $this->assertEquals('OK', $result['message']); + $this->assertEquals('success', $result['status']); + } +} From 62eb9666bde5c901adf3c45106fb6e1d8b17860c Mon Sep 17 00:00:00 2001 From: Kartik Jolapara Date: Thu, 12 Oct 2023 01:01:37 +0530 Subject: [PATCH 3/3] fix: add Netcore secret to github test workflow and docker-compose Signed-off-by: Kartik Jolapara --- .github/workflows/tests.yml | 1 + docker-compose.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 552b207d..4b612c96 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,6 +40,7 @@ jobs: VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }} VONAGE_TO: ${{ secrets.VONAGE_TO }} VONAGE_FROM: ${{ secrets.VONAGE_FROM }} + NETCORE_API_KEY: ${{ secrets.NETCORE_API_KEY }} run: | docker compose up -d --build sleep 5 diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..b21045a1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,7 @@ services: - VONAGE_API_SECRET - VONAGE_TO - VONAGE_FROM + - NETCORE_API_KEY build: context: . volumes: