From 4328c128c55ddfd567b85abb8264c61636403617 Mon Sep 17 00:00:00 2001 From: Omji Kushwaha Date: Thu, 19 Oct 2023 02:05:37 +0530 Subject: [PATCH 1/2] feat: added Mandrill email adapter --- .../Messaging/Adapters/Email/Mandrill.php | 69 +++++++++++++++++++ tests/e2e/Email/MandrillTest.php | 34 +++++++++ 2 files changed, 103 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/Email/Mandrill.php create mode 100644 tests/e2e/Email/MandrillTest.php diff --git a/src/Utopia/Messaging/Adapters/Email/Mandrill.php b/src/Utopia/Messaging/Adapters/Email/Mandrill.php new file mode 100644 index 00000000..b65ab731 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Email/Mandrill.php @@ -0,0 +1,69 @@ +request( + method: 'POST', + url: 'https://mandrillapp.com/api/1.0/messages/send', + headers: [ + 'Content-Type: application/json', + ], + body: \json_encode([ + "key" => $this->apiKey, + "message" => [ + "subject" => $message->getSubject(), + "html" => $message->isHTML() ? $message->getContent() : null, + "text" => $message->isHTML() ? null : $message->getContent(), + "from_email" => $message->getFrom(), + "to" => \array_map( + fn ($to) => ['email' => $to], + $message->getTo() + ), + ] + ]), + ); + } +} diff --git a/tests/e2e/Email/MandrillTest.php b/tests/e2e/Email/MandrillTest.php new file mode 100644 index 00000000..2b4e4e17 --- /dev/null +++ b/tests/e2e/Email/MandrillTest.php @@ -0,0 +1,34 @@ +send($message); + + $this->assertEquals($response, ''); + } +} From 06429cb69b8796e6a786301aedd9039e1dfb91b7 Mon Sep 17 00:00:00 2001 From: Omji Kushwaha Date: Fri, 20 Oct 2023 00:38:11 +0530 Subject: [PATCH 2/2] feat:added env and test --- .github/workflows/tests.yml | 1 + docker-compose.yml | 1 + tests/e2e/Email/MandrillTest.php | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 552b207d..a458488d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,6 +17,7 @@ jobs: MAILGUN_API_KEY: ${{ secrets.MAILGUN_API_KEY }} MAILGUN_DOMAIN: ${{ secrets.MAILGUN_DOMAIN }} SENDGRID_API_KEY: ${{ secrets.SENDGRID_API_KEY }} + MANDRILL_API_KEY: ${{ secrets.MANDRILL_API_KEY }} FCM_SERVER_KEY: ${{ secrets.FCM_SERVER_KEY }} FCM_SERVER_TO: ${{ secrets.FCM_SERVER_TO }} TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }} diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..ca2fb225 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: - MAILGUN_API_KEY - MAILGUN_DOMAIN - SENDGRID_API_KEY + - MANDRILL_API_KEY - FCM_SERVER_KEY - FCM_SERVER_TO - TWILIO_ACCOUNT_SID diff --git a/tests/e2e/Email/MandrillTest.php b/tests/e2e/Email/MandrillTest.php index 2b4e4e17..680f3ecb 100644 --- a/tests/e2e/Email/MandrillTest.php +++ b/tests/e2e/Email/MandrillTest.php @@ -27,8 +27,12 @@ public function testSendEmail() content: $content, ); - $response = $sender->send($message); + $response =json_decode($sender->send($message))[0]; - $this->assertEquals($response, ''); + $this->assertArrayHasKey('_id',$response); + $this->assertArrayHasKey('email',$response); + $this->assertArrayHasKey('status',$response); + $this->assertArrayHasKey('reject_reason',$response); + $this->assertArrayHasKey('queued_reason',$response); } }