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: 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; + } +} 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']); + } +}