Skip to content
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

Test torsten #21

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,97 @@
.idea
vendor
Makefile
.envrc
.env
*.p8

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### PHPUnit ###
# Covers PHPUnit
# Reference: https://phpunit.de/

# Generated files
.phpunit.result.cache
.phpunit.cache

# PHPUnit
/app/phpunit.xml
/phpunit.xml

# Build data
/build/

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/macos,linux,windows,phpunit
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "9.5.*",
"phpmailer/phpmailer": "6.6.*",
"phpunit/phpunit": "^9.6",
"phpmailer/phpmailer": "^6.8",
"laravel/pint": "^1.2"
},
"config": {
Expand Down
49 changes: 26 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@ version: '3.9'

services:
tests:
environment:
- MAILGUN_API_KEY
- MAILGUN_DOMAIN
- SENDGRID_API_KEY
- FCM_SERVER_KEY
- TWILIO_ACCOUNT_SID
- TWILIO_AUTH_TOKEN
- TELNYX_API_KEY
- TELNYX_PUBLIC_KEY
- APNS_AUTHKEY_8KVVCLA3HL
- APNS_AUTH_ID
- APNS_TEAM_ID
- APNS_BUNDLE_ID
- MSG_91_SENDER_ID
- MSG_91_AUTH_KEY
- TEST_EMAIL
- TEST_FROM_EMAIL
build:
context: .
volumes:
- ./src:/usr/local/src/src
- ./tests:/usr/local/src/tests
- ./phpunit.xml:/usr/local/src/phpunit.xml

maildev:
image: appwrite/mailcatcher:1.0.0
ports:
Expand Down
24 changes: 21 additions & 3 deletions src/Utopia/Messaging/Adapters/Email/Mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ class Mailgun extends EmailAdapter
public function __construct(
private string $apiKey,
private string $domain,
private bool $isUS = true
) {
}

/**
* Get adapter name.
*
* @return string
*/
public function getName(): string
{
return 'Mailgun';
}

/**
* Get adapter description.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
return 1000;
Expand All @@ -34,19 +45,26 @@ public function getMaxMessagesPerRequest(): int
*/
protected function process(Email $message): string
{
return $this->request(
$usDomain = 'api.mailgun.net';
$euDomain = 'api.eu.mailgun.net';

$domain = $this->isUS ? $usDomain : $euDomain;

$response = $this->request(
method: 'POST',
url: "https://api.mailgun.net/v3/{$this->domain}/messages",
url: "https://$domain/v3/{$this->domain}/messages",
headers: [
'Authorization: Basic '.base64_encode('api:'.$this->apiKey),
],
body: \http_build_query([
'from' => $message->getFrom(),
'to' => \implode(',', $message->getTo()),
'from' => $message->getFrom(),
'subject' => $message->getSubject(),
'text' => $message->isHtml() ? null : $message->getContent(),
'html' => $message->isHtml() ? $message->getContent() : null,
]),
);

return $response;
}
}
28 changes: 25 additions & 3 deletions src/Utopia/Messaging/Adapters/Email/Sendgrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,48 @@

namespace Utopia\Messaging\Adapters\Email;

use Exception;
use Utopia\Messaging\Adapters\Email as EmailAdapter;
use Utopia\Messaging\Messages\Email;

class Sendgrid extends EmailAdapter
{
public function __construct(
private string $apiKey,
) {
/**
* @param string $apiKey Your Sendgrid API key to authenticate with the API.
* @return void
*/
public function __construct(private string $apiKey)
{
}

/**
* Get adapter name.
*
* @return string
*/
public function getName(): string
{
return 'Sendgrid';
}

/**
* Get max messages per request.
*
* @return int
*/
public function getMaxMessagesPerRequest(): int
{
return 1000;
}

/**
* {@inheritdoc}
*
* @param Email $message
* @return string
*
* @throws Exception
*/
protected function process(Email $message): string
{
return $this->request(
Expand Down
Loading