-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add brevo adapter and test suite for the same. #34
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Utopia\Messaging\Adapters\Email; | ||
|
||
use Utopia\Messaging\Messages\Email; | ||
use Utopia\Messaging\Adapters\Email as EmailAdapter; | ||
|
||
class Brevo extends EmailAdapter | ||
{ | ||
public function __construct(private string $apiKey) | ||
{ | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'Brevo'; | ||
} | ||
|
||
public function getMaxMessagesPerRequest(): int | ||
{ | ||
return 1000; | ||
} | ||
|
||
protected function process(Email $message): string | ||
{ | ||
$bodyKey = $message->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(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do the same as in
|
||
]) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Tests\E2E; | ||
|
||
use Utopia\Messaging\Adapters\Email\Brevo; | ||
use Utopia\Messaging\Messages\Email; | ||
|
||
class BrevoTest extends Base | ||
{ | ||
/** | ||
* @throws \Exception | ||
*/ | ||
public function testSendPlainTextEmail() | ||
{ | ||
// $this->markTestSkipped('Brevo credentials not set.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove this? |
||
|
||
$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)); | ||
|
||
|
||
|
||
Comment on lines
+34
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove these empty lines? |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you link the documentation to support this in the PR description or as a response to this comment?