-
Notifications
You must be signed in to change notification settings - Fork 66
Feat 6396 Postmark Messaging Adapter #26
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
Open
thinkverse
wants to merge
9
commits into
utopia-php:main
Choose a base branch
from
thinkverse:feat-6396-postmark-messaging-adapter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
33dc01b
Add Postmark test suite
thinkverse 9b072d8
Add Postmark Email Adapter
thinkverse 440fd22
Skip Postmark E2E test by default
thinkverse eba1d85
Remove whitespace
thinkverse 9c1b73a
Fix linting error
thinkverse b714cc0
Add link to batch email limit
thinkverse b7db21c
Fix trailing whitespace in comment
thinkverse 468fb56
PR review changes
Meldiron 286d98f
Merge branch 'main' into feat-6396-postmark-messaging-adapter
thinkverse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Messaging\Adapters\Email; | ||
|
|
||
| use Utopia\Messaging\Adapters\Email as EmailAdapter; | ||
| use Utopia\Messaging\Messages\Email; | ||
|
|
||
| class Postmark extends EmailAdapter | ||
| { | ||
| /** | ||
| * @param string $apiKey Your Postmark API key to authenticate with the API. | ||
| */ | ||
| public function __construct( | ||
| private string $apiKey | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * Get adapter name. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getName(): string | ||
| { | ||
| return 'Postmark'; | ||
| } | ||
|
|
||
| /** | ||
| * 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 | ||
| { | ||
| return 50; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| * | ||
| * @throws \Exception | ||
| */ | ||
| protected function process(Email $message): string | ||
| { | ||
| $bodyKey = $message->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; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\E2E; | ||
|
|
||
| use Utopia\Messaging\Adapters\Email\Postmark; | ||
| use Utopia\Messaging\Messages\Email; | ||
|
|
||
| class PostmarkTest extends Base | ||
| { | ||
| /** | ||
| * @throws \Exception | ||
| */ | ||
| public function testSendPlainTextEmail() | ||
| { | ||
| $key = getenv('POSTMARK_API_KEY'); | ||
| $sender = new Postmark($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, | ||
| ); | ||
|
|
||
| $result = (array) \json_decode($sender->send($message)); | ||
|
|
||
| $this->assertEquals($to, $result['To']); | ||
| $this->assertEquals('OK', $result['Message']); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.