diff --git a/src/Utopia/Messaging/Adapters/Email/Brevo.php b/src/Utopia/Messaging/Adapters/Email/Brevo.php new file mode 100644 index 00000000..693b6b33 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Email/Brevo.php @@ -0,0 +1,48 @@ +isHtml() ? 'htmlContent' : 'textContent'; + return $this->request( + method: 'POST', + url: 'https://api.brevo.com/v3/smtp/email', + headers: [ + 'accept: application/json', + 'Content-Type: application/json', + 'api-key: '.$this->apiKey, + ], + body: \json_encode([ + "sender" => [ + "email" => $message->getFrom() + ], + "to" => \array_map( + fn ($to) => ['email' => $to], + $message->getTo() + ), + "subject" => $message->getSubject(), + $bodyKey => $message->getContent(), + ]) + ); + } +} diff --git a/tests/e2e/Email/BrevoTest.php b/tests/e2e/Email/BrevoTest.php new file mode 100644 index 00000000..24b34270 --- /dev/null +++ b/tests/e2e/Email/BrevoTest.php @@ -0,0 +1,38 @@ +markTestSkipped('Brevo credentials not set.'); + + $key = getenv('BREVO_API_KEY'); + $sender = new Brevo($key); + + $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, + ); + + $response = $sender->send($message); + $this->assertArrayHasKey('messageId', json_decode($response, true)); + + + + } +} \ No newline at end of file