-
Notifications
You must be signed in to change notification settings - Fork 68
Added Mailchimp Email Adapater #45
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
AVDiv
wants to merge
6
commits into
utopia-php:main
Choose a base branch
from
AVDiv:feat-6388-mailchimp-email-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 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98cbdca
Added Mailchimp adapter for transactional emails
AVDiv 7b33bb6
Added testing unit for mailchimp adapter
AVDiv 17bdbf1
Adjust env variables and docker-compose setup
AVDiv 02f422d
Resolved linting errors
AVDiv 6b42757
Test File: Object to Array Typecasting Error fixed
AVDiv 80c22d5
Update tests/e2e/Email/MailchimpTest.php
AVDiv 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,78 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Messaging\Adapters\Email; | ||
|
|
||
| use Utopia\Messaging\Adapters\Email as EmailAdapter; | ||
| use Utopia\Messaging\Messages\Email; | ||
|
|
||
| class Mailchimp extends EmailAdapter | ||
| { | ||
| /** | ||
| * @param string $apiKey Your Mailchimp API key to authenticate with the API. | ||
| */ | ||
| public function __construct( | ||
| private string $apiKey, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * Get adapter name. | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getName(): string | ||
| { | ||
| return 'Mailchimp'; | ||
| } | ||
|
|
||
| /** | ||
| * Get adapter description. | ||
| * | ||
| * @return int | ||
| */ | ||
| public function getMaxMessagesPerRequest(): int | ||
| { | ||
| return 1000; // Depends based on the pricing plan | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| * | ||
| * @param Email $message | ||
| * @return string | ||
| * | ||
| * @throws Exception | ||
| */ | ||
| protected function process(Email $message): string | ||
| { | ||
| return $this->request( | ||
| method: 'POST', | ||
| url: 'https://mandrillapp.com/api/1.0/messages/send', | ||
| headers: [ | ||
| 'Content-Type: application/json', | ||
| ], | ||
| body: \json_encode([ | ||
| 'key' => $this->apiKey, | ||
| 'message' => [ | ||
| 'html' => $message->isHtml() ? $message->getContent() : null, | ||
| 'text' => $message->isHtml() ? null : $message->getContent(), | ||
| 'subject' => $message->getSubject(), | ||
| 'from_email' => $message->getFrom(), | ||
| 'to' => \array_map( | ||
| fn ($to) => ['email' => $to], | ||
| $message->getTo() | ||
| ), | ||
| 'attachments' => $message->getAttachments() ? \array_map( | ||
| fn ($attachement) => [ | ||
| 'type' => $attachement['type'], | ||
| 'name' => $attachement['name'], | ||
| 'content' => $attachement['content'], | ||
| ], | ||
| $message->getAttachments() | ||
| ) : null, | ||
| ], | ||
| ] | ||
| ) | ||
| ); | ||
| } | ||
| } |
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,39 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\E2E; | ||
|
|
||
| use Utopia\Messaging\Adapters\Email\Mailchimp; | ||
| use Utopia\Messaging\Messages\Email; | ||
|
|
||
| class MailchimpTest extends Base | ||
| { | ||
| /** | ||
| * @throws \Exception | ||
| */ | ||
| public function testSendEmail() | ||
| { | ||
| $key = getenv('MAILCHIMP_API_KEY'); | ||
|
|
||
| $sender = new Mailchimp( | ||
| apiKey: $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))[0]; | ||
|
|
||
| $this->assertArrayHasKey('_id', $result); | ||
| $this->assertArrayHasKey('status', $result); | ||
| $this->assertTrue(str_contains(strtolower($result['status']), 'sent')); | ||
| } | ||
| } | ||
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.