diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 552b207d..5844f4c5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -40,6 +40,9 @@ jobs: VONAGE_API_SECRET: ${{ secrets.VONAGE_API_SECRET }} VONAGE_TO: ${{ secrets.VONAGE_TO }} VONAGE_FROM: ${{ secrets.VONAGE_FROM }} + SPARKPOST_API_KEY: ${{ secrets.SPARKPOST_API_KEY }} + SPARKPOST_TO: ${{ secrets.SPARKPOST_TO }} + SPARKPOST_FROM: ${{ secrets.SPARKPOST_FROM }} run: | docker compose up -d --build sleep 5 diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..34d107a2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,6 +29,9 @@ services: - VONAGE_API_SECRET - VONAGE_TO - VONAGE_FROM + - SPARKPOST_API_KEY + - SPARKPOST_TO + - SPARKPOST_FROM build: context: . volumes: diff --git a/src/Utopia/Messaging/Adapters/Email/SparkPost.php b/src/Utopia/Messaging/Adapters/Email/SparkPost.php new file mode 100644 index 00000000..33dfd6c3 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Email/SparkPost.php @@ -0,0 +1,71 @@ +isEu ? $euDomain : $usDomain; + + $requestBody = [ + 'options' =>[ + //for testing without domain set sandbox option to true(for more information, visit sparkpost.com) + 'sandbox' => false, + ], + 'recipients' => [ + [ + 'address' => [ + 'email' => $message->getTo()[0], // Assuming you have only one recipient + ], + ], + ], + 'content' => [ + // for testing with sandbox template id should be 'my-first-email' , so uncomment below line + // 'template_id' => 'my-first-email', + 'from' => [ + //sender domain should be registered and verified at sparkpost + 'email' => $message->getFrom(), + ], + //when testing with sandbox comment out below three lines + 'subject' => $message->getSubject(), + 'html' => $message->isHtml() ? $message->getContent() : null, + 'text' => $message->isHtml() ? null : $message->getContent(), + ], + ]; + + $json_body = json_encode($requestBody); + + $response = $this->request( + method: 'POST', + url: "https://$domain/api/v1/transmissions", + headers :[ + 'Authorization: '.$this->apiKey, + 'Content-Type: application/json', + ], + body: $json_body, + ); + + return $response; + } +} + +?> \ No newline at end of file diff --git a/tests/e2e/Email/SparkPostTest.php b/tests/e2e/Email/SparkPostTest.php new file mode 100644 index 00000000..0c5cc90c --- /dev/null +++ b/tests/e2e/Email/SparkPostTest.php @@ -0,0 +1,35 @@ +send($message); + $this->assertNotEmpty($response); + } +} +?> \ No newline at end of file