From 7ce783c49b00aa6a2d8572b481cb1dd07211cce8 Mon Sep 17 00:00:00 2001 From: Ayaan49 Date: Fri, 6 Oct 2023 09:07:08 +0530 Subject: [PATCH 1/6] Add SMTP2GO Email adapter --- Dockerfile | 9 +- composer.json | 6 +- composer.lock | 179 +++++++++--------- docker-compose.yml | 33 +--- .../Messaging/Adapters/Email/Smtp2go.php | 62 ++++++ tests/e2e/Email/Smtp2goTest.php | 48 +++++ 6 files changed, 218 insertions(+), 119 deletions(-) create mode 100644 src/Utopia/Messaging/Adapters/Email/Smtp2go.php create mode 100644 tests/e2e/Email/Smtp2goTest.php diff --git a/Dockerfile b/Dockerfile index 19d90e3a..7a856005 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# Stage 1: Composer FROM composer:2.0 as composer ARG TESTING=false @@ -15,6 +16,7 @@ RUN composer install \ --no-scripts \ --prefer-dist +# Stage 2: PHP FROM php:8.0-cli-alpine WORKDIR /usr/local/src/ @@ -22,4 +24,9 @@ WORKDIR /usr/local/src/ COPY --from=composer /usr/local/src/vendor /usr/local/src/vendor COPY . /usr/local/src/ -CMD [ "tail", "-f", "/dev/null" ] \ No newline at end of file +# Install PHPUnit +RUN wget -O phpunit https://phar.phpunit.de/phpunit-9.phar && \ + chmod +x phpunit && \ + mv phpunit /usr/local/bin/phpunit + +CMD [ "tail", "-f", "/dev/null" ] diff --git a/composer.json b/composer.json index bac108a5..7cc0fcc7 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }, "autoload": { "psr-4": { - "Utopia\\Messaging\\": "src/Utopia/Messaging" + "Utopia\\Messaging\\": "src/Utopia/Messaging/" } }, "autoload-dev": { @@ -26,8 +26,8 @@ "ext-curl": "*" }, "require-dev": { - "phpunit/phpunit": "9.6.*", - "phpmailer/phpmailer": "6.8.*", + "phpunit/phpunit": "^9.6", + "phpmailer/phpmailer": "^6.8", "laravel/pint": "^1.2" }, "config": { diff --git a/composer.lock b/composer.lock index 9f6b978b..eea229ad 100644 --- a/composer.lock +++ b/composer.lock @@ -4,35 +4,35 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5ecbd865cbd7f14e7819fb79643573be", + "content-hash": "9a5b54bf8cc5b2265f1ce16d43d58af9", "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.4.1", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^9 || ^11", "ext-pdo": "*", "ext-phar": "*", "phpbench/phpbench": "^0.16 || ^1", "phpstan/phpstan": "^1.4", "phpstan/phpstan-phpunit": "^1", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.22" + "vimeo/psalm": "^4.30 || ^5.4" }, "type": "library", "autoload": { @@ -59,7 +59,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.1" + "source": "https://github.com/doctrine/instantiator/tree/1.5.0" }, "funding": [ { @@ -75,20 +75,20 @@ "type": "tidelift" } ], - "time": "2022-03-03T08:28:38+00:00" + "time": "2022-12-30T00:15:36+00:00" }, { "name": "laravel/pint", - "version": "v1.2.0", + "version": "v1.5.0", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86" + "reference": "e0a8cef58b74662f27355be9cdea0e726bbac362" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/1d276e4c803397a26cc337df908f55c2a4e90d86", - "reference": "1d276e4c803397a26cc337df908f55c2a4e90d86", + "url": "https://api.github.com/repos/laravel/pint/zipball/e0a8cef58b74662f27355be9cdea0e726bbac362", + "reference": "e0a8cef58b74662f27355be9cdea0e726bbac362", "shasum": "" }, "require": { @@ -99,13 +99,13 @@ "php": "^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.11.0", - "illuminate/view": "^9.27", - "laravel-zero/framework": "^9.1.3", - "mockery/mockery": "^1.5.0", - "nunomaduro/larastan": "^2.2", - "nunomaduro/termwind": "^1.14.0", - "pestphp/pest": "^1.22.1" + "friendsofphp/php-cs-fixer": "^3.14.4", + "illuminate/view": "^9.51.0", + "laravel-zero/framework": "^9.2.0", + "mockery/mockery": "^1.5.1", + "nunomaduro/larastan": "^2.4.0", + "nunomaduro/termwind": "^1.15.1", + "pestphp/pest": "^1.22.4" }, "bin": [ "builds/pint" @@ -141,20 +141,20 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2022-09-13T15:07:15+00:00" + "time": "2023-02-14T16:31:02+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.11.0", + "version": "1.11.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614" + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/14daed4296fae74d9e3201d2c4925d1acb7aa614", - "reference": "14daed4296fae74d9e3201d2c4925d1acb7aa614", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", "shasum": "" }, "require": { @@ -192,7 +192,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" }, "funding": [ { @@ -200,20 +200,20 @@ "type": "tidelift" } ], - "time": "2022-03-03T13:19:32+00:00" + "time": "2023-03-08T13:26:56+00:00" }, { "name": "nikic/php-parser", - "version": "v4.15.1", + "version": "v4.17.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900" + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", - "reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", "shasum": "" }, "require": { @@ -254,9 +254,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" }, - "time": "2022-09-04T07:30:47+00:00" + "time": "2023-08-13T19:53:39+00:00" }, { "name": "phar-io/manifest", @@ -371,16 +371,16 @@ }, { "name": "phpmailer/phpmailer", - "version": "v6.8.0", + "version": "v6.8.1", "source": { "type": "git", "url": "https://github.com/PHPMailer/PHPMailer.git", - "reference": "df16b615e371d81fb79e506277faea67a1be18f1" + "reference": "e88da8d679acc3824ff231fdc553565b802ac016" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/df16b615e371d81fb79e506277faea67a1be18f1", - "reference": "df16b615e371d81fb79e506277faea67a1be18f1", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/e88da8d679acc3824ff231fdc553565b802ac016", + "reference": "e88da8d679acc3824ff231fdc553565b802ac016", "shasum": "" }, "require": { @@ -390,13 +390,13 @@ "php": ">=5.5.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.2", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "doctrine/annotations": "^1.2.6 || ^1.13.3", "php-parallel-lint/php-console-highlighter": "^1.0.0", "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9.3.5", "roave/security-advisories": "dev-latest", - "squizlabs/php_codesniffer": "^3.7.1", + "squizlabs/php_codesniffer": "^3.7.2", "yoast/phpunit-polyfills": "^1.0.4" }, "suggest": { @@ -439,7 +439,7 @@ "description": "PHPMailer is a full-featured email creation and transfer class for PHP", "support": { "issues": "https://github.com/PHPMailer/PHPMailer/issues", - "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.8.0" + "source": "https://github.com/PHPMailer/PHPMailer/tree/v6.8.1" }, "funding": [ { @@ -447,27 +447,27 @@ "type": "github" } ], - "time": "2023-03-06T14:43:22+00:00" + "time": "2023-08-29T08:26:30+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.17", + "version": "9.2.29", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8" + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa94dc41e8661fe90c7316849907cba3007b10d8", - "reference": "aa94dc41e8661fe90c7316849907cba3007b10d8", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76", + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.14", + "nikic/php-parser": "^4.15", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -482,8 +482,8 @@ "phpunit/phpunit": "^9.3" }, "suggest": { - "ext-pcov": "*", - "ext-xdebug": "*" + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" }, "type": "library", "extra": { @@ -516,7 +516,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.17" + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29" }, "funding": [ { @@ -524,7 +525,7 @@ "type": "github" } ], - "time": "2022-08-30T12:24:04+00:00" + "time": "2023-09-19T04:57:46+00:00" }, { "name": "phpunit/php-file-iterator", @@ -769,16 +770,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.10", + "version": "9.6.13", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328" + "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a6d351645c3fe5a30f5e86be6577d946af65a328", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3d767f7f9e191eab4189abe41ab37797e30b1be", + "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be", "shasum": "" }, "require": { @@ -793,7 +794,7 @@ "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.13", + "phpunit/php-code-coverage": "^9.2.28", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -852,7 +853,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.10" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.13" }, "funding": [ { @@ -868,7 +869,7 @@ "type": "tidelift" } ], - "time": "2023-07-10T04:04:23+00:00" + "time": "2023-09-19T05:39:22+00:00" }, { "name": "sebastian/cli-parser", @@ -1170,16 +1171,16 @@ }, { "name": "sebastian/diff", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d" + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", "shasum": "" }, "require": { @@ -1224,7 +1225,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" }, "funding": [ { @@ -1232,20 +1233,20 @@ "type": "github" } ], - "time": "2020-10-26T13:10:38+00:00" + "time": "2023-05-07T05:35:17+00:00" }, { "name": "sebastian/environment", - "version": "5.1.4", + "version": "5.1.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7" + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/1b5dff7bb151a4db11d49d90e5408e4e938270f7", - "reference": "1b5dff7bb151a4db11d49d90e5408e4e938270f7", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", "shasum": "" }, "require": { @@ -1287,7 +1288,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1.4" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" }, "funding": [ { @@ -1295,7 +1296,7 @@ "type": "github" } ], - "time": "2022-04-03T09:37:03+00:00" + "time": "2023-02-03T06:03:51+00:00" }, { "name": "sebastian/exporter", @@ -1376,16 +1377,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bde739e7565280bda77be70044ac1047bc007e34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", "shasum": "" }, "require": { @@ -1428,7 +1429,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" }, "funding": [ { @@ -1436,7 +1437,7 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2023-08-02T09:26:13+00:00" }, { "name": "sebastian/lines-of-code", @@ -1609,16 +1610,16 @@ }, { "name": "sebastian/recursion-context", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172" + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/cd9d8cf3c5804de4341c283ed787f099f5506172", - "reference": "cd9d8cf3c5804de4341c283ed787f099f5506172", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", "shasum": "" }, "require": { @@ -1657,10 +1658,10 @@ } ], "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "homepage": "https://github.com/sebastianbergmann/recursion-context", "support": { "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" }, "funding": [ { @@ -1668,7 +1669,7 @@ "type": "github" } ], - "time": "2020-10-26T13:17:30+00:00" + "time": "2023-02-03T06:07:39+00:00" }, { "name": "sebastian/resource-operations", @@ -1727,16 +1728,16 @@ }, { "name": "sebastian/type", - "version": "3.2.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e" + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", - "reference": "fb3fe09c5f0bae6bc27ef3ce933a1e0ed9464b6e", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", "shasum": "" }, "require": { @@ -1771,7 +1772,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.2.0" + "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" }, "funding": [ { @@ -1779,7 +1780,7 @@ "type": "github" } ], - "time": "2022-09-12T14:47:03+00:00" + "time": "2023-02-03T06:13:03+00:00" }, { "name": "sebastian/version", @@ -1898,5 +1899,5 @@ "platform-overrides": { "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/docker-compose.yml b/docker-compose.yml index 80d626d9..016ffa42 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,33 +2,14 @@ version: '3.9' services: tests: + image: my-php-app environment: - - MAILGUN_API_KEY - - MAILGUN_DOMAIN - - SENDGRID_API_KEY - - FCM_SERVER_KEY - - FCM_SERVER_TO - - TWILIO_ACCOUNT_SID - - TWILIO_AUTH_TOKEN - - TWILIO_TO - - TWILIO_FROM - - TELNYX_API_KEY - - TELNYX_PUBLIC_KEY - - APNS_AUTHKEY_8KVVCLA3HL - - APNS_AUTH_ID - - APNS_TEAM_ID - - APNS_BUNDLE_ID - - APNS_TO - - MSG_91_SENDER_ID - - MSG_91_AUTH_KEY - - MSG_91_TO - - MSG_91_FROM - - TEST_EMAIL - - TEST_FROM_EMAIL - - VONAGE_API_KEY - - VONAGE_API_SECRET - - VONAGE_TO - - VONAGE_FROM + - SMTP2GO_API_KEY=api-B87723D062A711EEAC22F23C91C88F4E + - SMTP2GO_USERNAME=ayaan49 + - SMTP2GO_PASSWORD=Ayaan@666 + - SMTP2GO_SERVER=mail.smtp2go.com + - SMTP2GO_PORT=2525 + build: context: . volumes: diff --git a/src/Utopia/Messaging/Adapters/Email/Smtp2go.php b/src/Utopia/Messaging/Adapters/Email/Smtp2go.php new file mode 100644 index 00000000..bfe80c37 --- /dev/null +++ b/src/Utopia/Messaging/Adapters/Email/Smtp2go.php @@ -0,0 +1,62 @@ +smtpServer = getenv('SMTP2GO_SERVER'); + $this->smtpUsername = getenv('SMTP2GO_USERNAME'); + $this->smtpPassword = getenv('SMTP2GO_PASSWORD'); + $this->smtpPort = getenv('SMTP2GO_PORT'); + + } + + public function getName(): string + { + return 'SMTP2GO'; + } + + public function getMaxMessagesPerRequest(): int + { + return 1; // SMTP2GO typically sends one email at a time + } + + protected function process(Email $message): string + { + // Create a PHPMailer instance + $mailer = new PHPMailer(); + + // Configure SMTP settings + $mailer->isSMTP(); + $mailer->Host = $this->smtpServer; + $mailer->SMTPAuth = true; + $mailer->Username = $this->smtpUsername; + $mailer->Password = $this->smtpPassword; + $mailer->Port = $this->smtpPort; + + // Set email content + $mailer->setFrom('ayaanbordoloi25@devfun.cloud', 'Ayaan'); + $mailer->addAddress('ayaansive25@gmail.com', 'Rohan'); + $mailer->Subject = 'Test Subject'; + $mailer->Body = 'Test mail'; + + // Send the email + if ($mailer->send()) { + return 'Email sent successfully'; + } else { + return 'Failed to send email: ' . $mailer->ErrorInfo; + } + } +} diff --git a/tests/e2e/Email/Smtp2goTest.php b/tests/e2e/Email/Smtp2goTest.php new file mode 100644 index 00000000..cd63f35b --- /dev/null +++ b/tests/e2e/Email/Smtp2goTest.php @@ -0,0 +1,48 @@ +assertNotEmpty($smtp2goUsername, 'SMTP2GO_USERNAME is not set'); + $this->assertNotEmpty($smtp2goPassword, 'SMTP2GO_PASSWORD is not set'); + $this->assertNotEmpty($smtp2goServer, 'SMTP2GO_SERVER is not set'); + $this->assertNotEmpty($smtp2goPort, 'SMTP2GO_PORT is not set'); + + // Instantiate the SMTP2GO adapter + $sender = new Smtp2go($smtp2goServer, $smtp2goPort, $smtp2goUsername, $smtp2goPassword); + + + // Email details + $to = 'ayaansive25@gmail.com'; + $subject = 'Test Subject'; + $content = 'Test Content'; + $from = 'ayaanbordoloi25@devfun.cloud'; + + // Create an email message + $message = new Email( + to: [$to], + subject: $subject, + content: $content, + from: $from + ); + + // Send the email using SMTP2GO + $result = $sender->send($message); + + // Assert that the email was sent successfully + $this->assertTrue($result, 'Email sending failed'); + } +} From f03eae8ffcccf7a37351136c7d63b13af9d0108f Mon Sep 17 00:00:00 2001 From: Ayaan49 Date: Wed, 11 Oct 2023 03:01:58 +0530 Subject: [PATCH 2/6] Improve Appwrite Messaging with SMTP2GO Adapter --- docker-compose.yml | 35 ++++++++++++++++--- .../Messaging/Adapters/Email/Smtp2go.php | 33 +++++++---------- tests/e2e/Email/Smtp2goTest.php | 11 +++--- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 016ffa42..9b2b8387 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,11 +4,36 @@ services: tests: image: my-php-app environment: - - SMTP2GO_API_KEY=api-B87723D062A711EEAC22F23C91C88F4E - - SMTP2GO_USERNAME=ayaan49 - - SMTP2GO_PASSWORD=Ayaan@666 - - SMTP2GO_SERVER=mail.smtp2go.com - - SMTP2GO_PORT=2525 + - SMTP2GO_USERNAME + - SMTP2GO_PASSWORD + - SMTP2GO_SERVER + - SMTP2GO_PORT + - MAILGUN_API_KEY + - MAILGUN_DOMAIN + - SENDGRID_API_KEY + - FCM_SERVER_KEY + - FCM_SERVER_TO + - TWILIO_ACCOUNT_SID + - TWILIO_AUTH_TOKEN + - TWILIO_TO + - TWILIO_FROM + - TELNYX_API_KEY + - TELNYX_PUBLIC_KEY + - APNS_AUTHKEY_8KVVCLA3HL + - APNS_AUTH_ID + - APNS_TEAM_ID + - APNS_BUNDLE_ID + - APNS_TO + - MSG_91_SENDER_ID + - MSG_91_AUTH_KEY + - MSG_91_TO + - MSG_91_FROM + - TEST_EMAIL + - TEST_FROM_EMAIL + - VONAGE_API_KEY + - VONAGE_API_SECRET + - VONAGE_TO + - VONAGE_FROM build: context: . diff --git a/src/Utopia/Messaging/Adapters/Email/Smtp2go.php b/src/Utopia/Messaging/Adapters/Email/Smtp2go.php index bfe80c37..98a805d1 100644 --- a/src/Utopia/Messaging/Adapters/Email/Smtp2go.php +++ b/src/Utopia/Messaging/Adapters/Email/Smtp2go.php @@ -8,21 +8,6 @@ class Smtp2go extends EmailAdapter { - private string $smtpServer; - private string $smtpUsername; - private string $smtpPassword; - private int $smtpPort; - - public function __construct() - { - // Retrieve SMTP server details from environment variables - $this->smtpServer = getenv('SMTP2GO_SERVER'); - $this->smtpUsername = getenv('SMTP2GO_USERNAME'); - $this->smtpPassword = getenv('SMTP2GO_PASSWORD'); - $this->smtpPort = getenv('SMTP2GO_PORT'); - - } - public function getName(): string { return 'SMTP2GO'; @@ -35,20 +20,26 @@ public function getMaxMessagesPerRequest(): int protected function process(Email $message): string { + // Retrieve SMTP server details from environment variables + $smtpUsername = getenv('SMTP2GO_USERNAME'); + $smtpPassword = getenv('SMTP2GO_PASSWORD'); + $smtpServer = getenv('SMTP2GO_SERVER'); + $smtpPort = getenv('SMTP2GO_PORT'); + // Create a PHPMailer instance $mailer = new PHPMailer(); // Configure SMTP settings $mailer->isSMTP(); - $mailer->Host = $this->smtpServer; + $mailer->Username = $smtpUsername; + $mailer->Password = $smtpPassword; + $mailer->Host = $smtpServer; + $mailer->Port = $smtpPort; $mailer->SMTPAuth = true; - $mailer->Username = $this->smtpUsername; - $mailer->Password = $this->smtpPassword; - $mailer->Port = $this->smtpPort; // Set email content - $mailer->setFrom('ayaanbordoloi25@devfun.cloud', 'Ayaan'); - $mailer->addAddress('ayaansive25@gmail.com', 'Rohan'); + $mailer->setFrom('Senders-email', 'Name'); + $mailer->addAddress('Receivers-email', 'Name'); $mailer->Subject = 'Test Subject'; $mailer->Body = 'Test mail'; diff --git a/tests/e2e/Email/Smtp2goTest.php b/tests/e2e/Email/Smtp2goTest.php index cd63f35b..0919c429 100644 --- a/tests/e2e/Email/Smtp2goTest.php +++ b/tests/e2e/Email/Smtp2goTest.php @@ -23,13 +23,12 @@ public function testSendEmailWithSmtp2go() // Instantiate the SMTP2GO adapter $sender = new Smtp2go($smtp2goServer, $smtp2goPort, $smtp2goUsername, $smtp2goPassword); - // Email details - $to = 'ayaansive25@gmail.com'; + $to = 'Receivers-email'; $subject = 'Test Subject'; $content = 'Test Content'; - $from = 'ayaanbordoloi25@devfun.cloud'; + $from = 'Senders-email'; // Create an email message $message = new Email( @@ -38,11 +37,11 @@ public function testSendEmailWithSmtp2go() content: $content, from: $from ); - + // Send the email using SMTP2GO $result = $sender->send($message); - // Assert that the email was sent successfully - $this->assertTrue($result, 'Email sending failed'); + // Check if the email was sent successfully + $this->assertEquals('Email sent successfully', $result); } } From 1f5bc2bbed184675b82a4e79cf7f06742d010c40 Mon Sep 17 00:00:00 2001 From: Ayaan49 Date: Tue, 31 Oct 2023 15:14:38 +0530 Subject: [PATCH 3/6] Fix linting errors --- src/Utopia/Messaging/Adapter.php | 8 ----- .../Messaging/Adapters/Email/Mailgun.php | 4 --- .../Messaging/Adapters/Email/Sendgrid.php | 6 ---- .../Messaging/Adapters/Email/Smtp2go.php | 6 ++-- src/Utopia/Messaging/Adapters/Push/APNS.php | 12 -------- src/Utopia/Messaging/Adapters/Push/FCM.php | 4 --- src/Utopia/Messaging/Messages/Email.php | 18 ----------- src/Utopia/Messaging/Messages/Push.php | 30 ------------------- src/Utopia/Messaging/Messages/SMS.php | 12 -------- 9 files changed, 3 insertions(+), 97 deletions(-) diff --git a/src/Utopia/Messaging/Adapter.php b/src/Utopia/Messaging/Adapter.php index 60a909ef..df122c9b 100644 --- a/src/Utopia/Messaging/Adapter.php +++ b/src/Utopia/Messaging/Adapter.php @@ -6,29 +6,21 @@ abstract class Adapter { /** * Get the name of the adapter. - * - * @return string */ abstract public function getName(): string; /** * Get the type of the adapter. - * - * @return string */ abstract public function getType(): string; /** * Get the type of the message the adapter can send. - * - * @return string */ abstract public function getMessageType(): string; /** * Get the maximum number of messages that can be sent in a single request. - * - * @return int */ abstract public function getMaxMessagesPerRequest(): int; diff --git a/src/Utopia/Messaging/Adapters/Email/Mailgun.php b/src/Utopia/Messaging/Adapters/Email/Mailgun.php index 4e3882e8..09ad8895 100644 --- a/src/Utopia/Messaging/Adapters/Email/Mailgun.php +++ b/src/Utopia/Messaging/Adapters/Email/Mailgun.php @@ -20,8 +20,6 @@ public function __construct( /** * Get adapter name. - * - * @return string */ public function getName(): string { @@ -30,8 +28,6 @@ public function getName(): string /** * Get adapter description. - * - * @return int */ public function getMaxMessagesPerRequest(): int { diff --git a/src/Utopia/Messaging/Adapters/Email/Sendgrid.php b/src/Utopia/Messaging/Adapters/Email/Sendgrid.php index e91c31cc..18dccc20 100644 --- a/src/Utopia/Messaging/Adapters/Email/Sendgrid.php +++ b/src/Utopia/Messaging/Adapters/Email/Sendgrid.php @@ -17,8 +17,6 @@ public function __construct(private string $apiKey) /** * Get adapter name. - * - * @return string */ public function getName(): string { @@ -27,8 +25,6 @@ public function getName(): string /** * Get max messages per request. - * - * @return int */ public function getMaxMessagesPerRequest(): int { @@ -38,8 +34,6 @@ public function getMaxMessagesPerRequest(): int /** * {@inheritdoc} * - * @param Email $message - * @return string * * @throws Exception */ diff --git a/src/Utopia/Messaging/Adapters/Email/Smtp2go.php b/src/Utopia/Messaging/Adapters/Email/Smtp2go.php index 98a805d1..415784b5 100644 --- a/src/Utopia/Messaging/Adapters/Email/Smtp2go.php +++ b/src/Utopia/Messaging/Adapters/Email/Smtp2go.php @@ -2,9 +2,9 @@ namespace Utopia\Messaging\Adapters\Email; -use Utopia\Messaging\Messages\Email; -use Utopia\Messaging\Adapters\Email as EmailAdapter; use PHPMailer\PHPMailer\PHPMailer; +use Utopia\Messaging\Adapters\Email as EmailAdapter; +use Utopia\Messaging\Messages\Email; class Smtp2go extends EmailAdapter { @@ -47,7 +47,7 @@ protected function process(Email $message): string if ($mailer->send()) { return 'Email sent successfully'; } else { - return 'Failed to send email: ' . $mailer->ErrorInfo; + return 'Failed to send email: '.$mailer->ErrorInfo; } } } diff --git a/src/Utopia/Messaging/Adapters/Push/APNS.php b/src/Utopia/Messaging/Adapters/Push/APNS.php index 56282d83..559fb6d7 100644 --- a/src/Utopia/Messaging/Adapters/Push/APNS.php +++ b/src/Utopia/Messaging/Adapters/Push/APNS.php @@ -9,11 +9,6 @@ class APNS extends PushAdapter { /** - * @param string $authKey - * @param string $authKeyId - * @param string $teamId - * @param string $bundleId - * @param string $endpoint * @return void */ public function __construct( @@ -27,8 +22,6 @@ public function __construct( /** * Get adapter name. - * - * @return string */ public function getName(): string { @@ -37,8 +30,6 @@ public function getName(): string /** * Get max messages per request. - * - * @return int */ public function getMaxMessagesPerRequest(): int { @@ -48,8 +39,6 @@ public function getMaxMessagesPerRequest(): int /** * {@inheritdoc} * - * @param Push $message - * @return string * * @throws Exception */ @@ -179,7 +168,6 @@ function ($value) { /** * Generate JWT. * - * @return string * * @throws Exception */ diff --git a/src/Utopia/Messaging/Adapters/Push/FCM.php b/src/Utopia/Messaging/Adapters/Push/FCM.php index 8a4d8ac2..4a028f62 100644 --- a/src/Utopia/Messaging/Adapters/Push/FCM.php +++ b/src/Utopia/Messaging/Adapters/Push/FCM.php @@ -17,8 +17,6 @@ public function __construct( /** * Get adapter name. - * - * @return string */ public function getName(): string { @@ -27,8 +25,6 @@ public function getName(): string /** * Get max messages per request. - * - * @return int */ public function getMaxMessagesPerRequest(): int { diff --git a/src/Utopia/Messaging/Messages/Email.php b/src/Utopia/Messaging/Messages/Email.php index 21fedeea..545b1d54 100644 --- a/src/Utopia/Messaging/Messages/Email.php +++ b/src/Utopia/Messaging/Messages/Email.php @@ -24,49 +24,31 @@ public function __construct( ) { } - /** - * @return array - */ public function getTo(): array { return $this->to; } - /** - * @return string - */ public function getSubject(): string { return $this->subject; } - /** - * @return string - */ public function getContent(): string { return $this->content; } - /** - * @return string|null - */ public function getFrom(): ?string { return $this->from; } - /** - * @return array|null - */ public function getAttachments(): ?array { return $this->attachments; } - /** - * @return bool - */ public function isHtml(): bool { return $this->html; diff --git a/src/Utopia/Messaging/Messages/Push.php b/src/Utopia/Messaging/Messages/Push.php index 93b8f5d7..337d0fbd 100644 --- a/src/Utopia/Messaging/Messages/Push.php +++ b/src/Utopia/Messaging/Messages/Push.php @@ -32,9 +32,6 @@ public function __construct( ) { } - /** - * @return array - */ public function getTo(): array { return $this->to; @@ -45,73 +42,46 @@ public function getFrom(): ?string return null; } - /** - * @return string - */ public function getTitle(): string { return $this->title; } - /** - * @return string - */ public function getBody(): string { return $this->body; } - /** - * @return array|null - */ public function getData(): ?array { return $this->data; } - /** - * @return string|null - */ public function getAction(): ?string { return $this->action; } - /** - * @return string|null - */ public function getSound(): ?string { return $this->sound; } - /** - * @return string|null - */ public function getIcon(): ?string { return $this->icon; } - /** - * @return string|null - */ public function getColor(): ?string { return $this->color; } - /** - * @return string|null - */ public function getTag(): ?string { return $this->tag; } - /** - * @return string|null - */ public function getBadge(): ?string { return $this->badge; diff --git a/src/Utopia/Messaging/Messages/SMS.php b/src/Utopia/Messaging/Messages/SMS.php index bcb913c0..31be8d99 100644 --- a/src/Utopia/Messaging/Messages/SMS.php +++ b/src/Utopia/Messaging/Messages/SMS.php @@ -14,33 +14,21 @@ public function __construct( ) { } - /** - * @return array - */ public function getTo(): array { return $this->to; } - /** - * @return string - */ public function getContent(): string { return $this->content; } - /** - * @return string|null - */ public function getFrom(): ?string { return $this->from; } - /** - * @return array|null - */ public function getAttachments(): ?array { return $this->attachments; From da2f320391e8eed9f906459fa827f06ac20f2c75 Mon Sep 17 00:00:00 2001 From: "Ayaan B. Bordoloi" Date: Fri, 3 Nov 2023 03:58:17 +0530 Subject: [PATCH 4/6] Update docker-compose.yml --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9b2b8387..fe62835f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.9' services: tests: - image: my-php-app + environment: - SMTP2GO_USERNAME - SMTP2GO_PASSWORD @@ -50,4 +50,4 @@ services: request-catcher: image: appwrite/requestcatcher:1.0.0 ports: - - '10001:5000' \ No newline at end of file + - '10001:5000' From dcf97282df1b15e21615ef71237f8a59efe38ea5 Mon Sep 17 00:00:00 2001 From: "Ayaan B. Bordoloi" Date: Fri, 3 Nov 2023 03:59:02 +0530 Subject: [PATCH 5/6] Update Dockerfile --- Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a856005..abb97006 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,9 +24,6 @@ WORKDIR /usr/local/src/ COPY --from=composer /usr/local/src/vendor /usr/local/src/vendor COPY . /usr/local/src/ -# Install PHPUnit -RUN wget -O phpunit https://phar.phpunit.de/phpunit-9.phar && \ - chmod +x phpunit && \ - mv phpunit /usr/local/bin/phpunit + CMD [ "tail", "-f", "/dev/null" ] From 31efa0167374105c987d489e2fedcddc9112a0ac Mon Sep 17 00:00:00 2001 From: "Ayaan B. Bordoloi" Date: Fri, 3 Nov 2023 04:00:13 +0530 Subject: [PATCH 6/6] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 7cc0fcc7..bac108a5 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }, "autoload": { "psr-4": { - "Utopia\\Messaging\\": "src/Utopia/Messaging/" + "Utopia\\Messaging\\": "src/Utopia/Messaging" } }, "autoload-dev": { @@ -26,8 +26,8 @@ "ext-curl": "*" }, "require-dev": { - "phpunit/phpunit": "^9.6", - "phpmailer/phpmailer": "^6.8", + "phpunit/phpunit": "9.6.*", + "phpmailer/phpmailer": "6.8.*", "laravel/pint": "^1.2" }, "config": {