From 33dc01b85178b41fbe14097b1acbbf58987d5894 Mon Sep 17 00:00:00 2001 From: Kim Hallberg Date: Mon, 2 Oct 2023 04:19:35 +0200 Subject: [PATCH 1/8] Add Postmark test suite --- tests/e2e/Email/PostmarkTest.php | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/e2e/Email/PostmarkTest.php diff --git a/tests/e2e/Email/PostmarkTest.php b/tests/e2e/Email/PostmarkTest.php new file mode 100644 index 00000000..268e506e --- /dev/null +++ b/tests/e2e/Email/PostmarkTest.php @@ -0,0 +1,35 @@ +send($message)); + + $this->assertEquals($to, $result['To']); + $this->assertEquals("OK", $result['Message']); + } +} From 9b072d886caa6b1d7d279b5c052e87231ad9d939 Mon Sep 17 00:00:00 2001 From: Kim Hallberg Date: Mon, 2 Oct 2023 04:20:10 +0200 Subject: [PATCH 2/8] Add Postmark Email Adapter --- .../Messaging/Adapters/Email/Postmark.php | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/Utopia/Messaging/Adapters/Email/Postmark.php diff --git a/src/Utopia/Messaging/Adapters/Email/Postmark.php b/src/Utopia/Messaging/Adapters/Email/Postmark.php new file mode 100644 index 00000000..ce7ff0c0 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Email/Postmark.php @@ -0,0 +1,66 @@ +isHtml() ? 'HtmlBody' : 'TextBody'; + + $response = $this->request( + method: 'POST', + url: "https://api.postmarkapp.com/email", + headers: [ + 'Accept: application/json', + 'Content-Type: application/json', + 'X-Postmark-Server-Token: '.$this->apiKey, + ], + body: \json_encode([ + 'To' => \implode(',', $message->getTo()), + 'From' => $message->getFrom(), + 'Subject' => $message->getSubject(), + $bodyKey => $message->getContent(), + ]), + ); + + return $response; + } +} From 440fd2215329c499f60381911b0af8ac235efe6e Mon Sep 17 00:00:00 2001 From: Kim Hallberg Date: Mon, 2 Oct 2023 05:03:13 +0200 Subject: [PATCH 3/8] Skip Postmark E2E test by default --- tests/e2e/Email/PostmarkTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/e2e/Email/PostmarkTest.php b/tests/e2e/Email/PostmarkTest.php index 268e506e..b64733d5 100644 --- a/tests/e2e/Email/PostmarkTest.php +++ b/tests/e2e/Email/PostmarkTest.php @@ -12,6 +12,8 @@ class PostmarkTest extends Base */ public function testSendPlainTextEmail() { + $this->markTestSkipped('Postmark credentials not set.'); + $key = getenv('POSTMARK_API_KEY'); $sender = new Postmark($key); From eba1d85f7ebaf4646d4689e343016f98b6165da6 Mon Sep 17 00:00:00 2001 From: Kim Hallberg Date: Mon, 2 Oct 2023 05:10:44 +0200 Subject: [PATCH 4/8] Remove whitespace --- src/Utopia/Messaging/Adapters/Email/Postmark.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/Email/Postmark.php b/src/Utopia/Messaging/Adapters/Email/Postmark.php index ce7ff0c0..a8643e22 100644 --- a/src/Utopia/Messaging/Adapters/Email/Postmark.php +++ b/src/Utopia/Messaging/Adapters/Email/Postmark.php @@ -1,6 +1,5 @@ Date: Thu, 5 Oct 2023 17:55:23 +0200 Subject: [PATCH 5/8] Fix linting error --- src/Utopia/Messaging/Adapters/Email/Postmark.php | 2 +- tests/e2e/Email/PostmarkTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utopia/Messaging/Adapters/Email/Postmark.php b/src/Utopia/Messaging/Adapters/Email/Postmark.php index a8643e22..58c5d93f 100644 --- a/src/Utopia/Messaging/Adapters/Email/Postmark.php +++ b/src/Utopia/Messaging/Adapters/Email/Postmark.php @@ -46,7 +46,7 @@ protected function process(Email $message): string $response = $this->request( method: 'POST', - url: "https://api.postmarkapp.com/email", + url: 'https://api.postmarkapp.com/email', headers: [ 'Accept: application/json', 'Content-Type: application/json', diff --git a/tests/e2e/Email/PostmarkTest.php b/tests/e2e/Email/PostmarkTest.php index b64733d5..bf73dc88 100644 --- a/tests/e2e/Email/PostmarkTest.php +++ b/tests/e2e/Email/PostmarkTest.php @@ -32,6 +32,6 @@ public function testSendPlainTextEmail() $result = (array) \json_decode($sender->send($message)); $this->assertEquals($to, $result['To']); - $this->assertEquals("OK", $result['Message']); + $this->assertEquals('OK', $result['Message']); } } From b714cc01a7673a15a27e339fa49f7b9b5030d2a7 Mon Sep 17 00:00:00 2001 From: Kim Hallberg Date: Wed, 1 Nov 2023 01:57:48 +0100 Subject: [PATCH 6/8] Add link to batch email limit --- src/Utopia/Messaging/Adapters/Email/Postmark.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Utopia/Messaging/Adapters/Email/Postmark.php b/src/Utopia/Messaging/Adapters/Email/Postmark.php index 58c5d93f..8d46bd81 100644 --- a/src/Utopia/Messaging/Adapters/Email/Postmark.php +++ b/src/Utopia/Messaging/Adapters/Email/Postmark.php @@ -28,6 +28,8 @@ public function getName(): string /** * Get adapter description. * + * @see https://postmarkapp.com/developer/api/email-api#send-batch-emails For information about batch email limit. + * * @return int */ public function getMaxMessagesPerRequest(): int From b7db21c335e73d83d90a9f9faaed6667901f1709 Mon Sep 17 00:00:00 2001 From: Kim Hallberg Date: Wed, 1 Nov 2023 18:02:03 +0100 Subject: [PATCH 7/8] Fix trailing whitespace in comment --- src/Utopia/Messaging/Adapters/Email/Postmark.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utopia/Messaging/Adapters/Email/Postmark.php b/src/Utopia/Messaging/Adapters/Email/Postmark.php index 8d46bd81..59179e68 100644 --- a/src/Utopia/Messaging/Adapters/Email/Postmark.php +++ b/src/Utopia/Messaging/Adapters/Email/Postmark.php @@ -29,7 +29,7 @@ public function getName(): string * Get adapter description. * * @see https://postmarkapp.com/developer/api/email-api#send-batch-emails For information about batch email limit. - * + * * @return int */ public function getMaxMessagesPerRequest(): int From 468fb5670714f33dd9b3d046485e20cc14bd5d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 21 Nov 2023 12:05:51 +0000 Subject: [PATCH 8/8] PR review changes --- docker-compose.yml | 1 + tests/e2e/Email/PostmarkTest.php | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..8f2dcc8a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,7 @@ services: environment: - MAILGUN_API_KEY - MAILGUN_DOMAIN + - POSTMARK_API_KEY - SENDGRID_API_KEY - FCM_SERVER_KEY - FCM_SERVER_TO diff --git a/tests/e2e/Email/PostmarkTest.php b/tests/e2e/Email/PostmarkTest.php index bf73dc88..8bbcab76 100644 --- a/tests/e2e/Email/PostmarkTest.php +++ b/tests/e2e/Email/PostmarkTest.php @@ -12,8 +12,6 @@ class PostmarkTest extends Base */ public function testSendPlainTextEmail() { - $this->markTestSkipped('Postmark credentials not set.'); - $key = getenv('POSTMARK_API_KEY'); $sender = new Postmark($key);