Browse Source

feat: resend email service

Cat 1 year ago
parent
commit
6e6d6f75f0

+ 1 - 0
composer.json

@@ -34,6 +34,7 @@
         "phpmailer/phpmailer": "^6",
         "postal/postal": "^2",
         "ramsey/uuid": "^4",
+        "resend/resend-php": "^0.12.0",
         "sendgrid/sendgrid": "^8",
         "sentry/sdk": "^4",
         "slim/http": "^1",

+ 104 - 46
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "ac5ceda957860eaa6035deeb1d458258",
+    "content-hash": "c26663c49583c6d735452b4e336378f9",
     "packages": [
         {
             "name": "adbario/php-dot-notation",
@@ -141,16 +141,16 @@
         },
         {
             "name": "alibabacloud/darabonba-openapi",
-            "version": "0.2.11",
+            "version": "0.2.12",
             "source": {
                 "type": "git",
                 "url": "https://github.com/alibabacloud-sdk-php/darabonba-openapi.git",
-                "reference": "1b5c5fc771eaf782cb792f9e975b8247683307c7"
+                "reference": "11617627ba6cf012732e7d9e165328ebaef2bc74"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/alibabacloud-sdk-php/darabonba-openapi/zipball/1b5c5fc771eaf782cb792f9e975b8247683307c7",
-                "reference": "1b5c5fc771eaf782cb792f9e975b8247683307c7",
+                "url": "https://api.github.com/repos/alibabacloud-sdk-php/darabonba-openapi/zipball/11617627ba6cf012732e7d9e165328ebaef2bc74",
+                "reference": "11617627ba6cf012732e7d9e165328ebaef2bc74",
                 "shasum": ""
             },
             "require": {
@@ -180,9 +180,9 @@
             "description": "Alibaba Cloud OpenApi Client",
             "support": {
                 "issues": "https://github.com/alibabacloud-sdk-php/darabonba-openapi/issues",
-                "source": "https://github.com/alibabacloud-sdk-php/darabonba-openapi/tree/0.2.11"
+                "source": "https://github.com/alibabacloud-sdk-php/darabonba-openapi/tree/0.2.12"
             },
-            "time": "2024-05-14T03:00:59+00:00"
+            "time": "2024-06-21T09:46:09+00:00"
         },
         {
             "name": "alibabacloud/dm-20170622",
@@ -510,12 +510,12 @@
             "source": {
                 "type": "git",
                 "url": "https://github.com/alipay/alipay-sdk-php-all.git",
-                "reference": "fa2be77aa421fff025c0adbc94ca3a7288e9be93"
+                "reference": "d706425b49be7e9ac294b915853c7069ea05c1d3"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/alipay/alipay-sdk-php-all/zipball/fa2be77aa421fff025c0adbc94ca3a7288e9be93",
-                "reference": "fa2be77aa421fff025c0adbc94ca3a7288e9be93",
+                "url": "https://api.github.com/repos/alipay/alipay-sdk-php-all/zipball/d706425b49be7e9ac294b915853c7069ea05c1d3",
+                "reference": "d706425b49be7e9ac294b915853c7069ea05c1d3",
                 "shasum": ""
             },
             "require": {
@@ -564,7 +564,7 @@
             "support": {
                 "source": "https://github.com/alipay/alipay-sdk-php-all/tree/master"
             },
-            "time": "2024-05-29T07:41:36+00:00"
+            "time": "2024-06-24T02:03:42+00:00"
         },
         {
             "name": "aws/aws-crt-php",
@@ -622,16 +622,16 @@
         },
         {
             "name": "aws/aws-sdk-php",
-            "version": "3.314.6",
+            "version": "3.314.7",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
-                "reference": "d04da330b0201edab71edd33a03b8d5ad6e4a313"
+                "reference": "3a7ea3e49ae50eaaa969dc15d69b2dd46b4d7284"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/d04da330b0201edab71edd33a03b8d5ad6e4a313",
-                "reference": "d04da330b0201edab71edd33a03b8d5ad6e4a313",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/3a7ea3e49ae50eaaa969dc15d69b2dd46b4d7284",
+                "reference": "3a7ea3e49ae50eaaa969dc15d69b2dd46b4d7284",
                 "shasum": ""
             },
             "require": {
@@ -711,9 +711,9 @@
             "support": {
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.314.6"
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.314.7"
             },
-            "time": "2024-06-20T18:09:51+00:00"
+            "time": "2024-06-24T21:03:27+00:00"
         },
         {
             "name": "bacon/bacon-qr-code",
@@ -4111,16 +4111,16 @@
         },
         {
             "name": "psr/http-message",
-            "version": "1.1",
+            "version": "2.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/php-fig/http-message.git",
-                "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba"
+                "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba",
-                "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba",
+                "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71",
+                "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71",
                 "shasum": ""
             },
             "require": {
@@ -4129,7 +4129,7 @@
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "1.1.x-dev"
+                    "dev-master": "2.0.x-dev"
                 }
             },
             "autoload": {
@@ -4144,7 +4144,7 @@
             "authors": [
                 {
                     "name": "PHP-FIG",
-                    "homepage": "http://www.php-fig.org/"
+                    "homepage": "https://www.php-fig.org/"
                 }
             ],
             "description": "Common interface for HTTP messages",
@@ -4158,9 +4158,9 @@
                 "response"
             ],
             "support": {
-                "source": "https://github.com/php-fig/http-message/tree/1.1"
+                "source": "https://github.com/php-fig/http-message/tree/2.0"
             },
-            "time": "2023-04-04T09:50:52+00:00"
+            "time": "2023-04-04T09:54:51+00:00"
         },
         {
             "name": "psr/http-server-handler",
@@ -4601,6 +4601,63 @@
             ],
             "time": "2024-04-27T21:32:50+00:00"
         },
+        {
+            "name": "resend/resend-php",
+            "version": "v0.12.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/resend/resend-php.git",
+                "reference": "37fb79bb8160ce2de521bf37484ba59e89236521"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/resend/resend-php/zipball/37fb79bb8160ce2de521bf37484ba59e89236521",
+                "reference": "37fb79bb8160ce2de521bf37484ba59e89236521",
+                "shasum": ""
+            },
+            "require": {
+                "guzzlehttp/guzzle": "^7.5",
+                "php": "^8.1.0"
+            },
+            "require-dev": {
+                "friendsofphp/php-cs-fixer": "^3.13",
+                "mockery/mockery": "^1.6",
+                "pestphp/pest": "^2.0"
+            },
+            "type": "library",
+            "autoload": {
+                "files": [
+                    "src/Resend.php"
+                ],
+                "psr-4": {
+                    "Resend\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Resend and contributors",
+                    "homepage": "https://github.com/resend/resend-php/contributors"
+                }
+            ],
+            "description": "Resend PHP library.",
+            "homepage": "https://resend.com/",
+            "keywords": [
+                "api",
+                "client",
+                "php",
+                "resend",
+                "sdk"
+            ],
+            "support": {
+                "issues": "https://github.com/resend/resend-php/issues",
+                "source": "https://github.com/resend/resend-php/tree/v0.12.0"
+            },
+            "time": "2024-03-04T03:16:28+00:00"
+        },
         {
             "name": "sendgrid/php-http-client",
             "version": "4.1.1",
@@ -4874,16 +4931,16 @@
         },
         {
             "name": "slim/http",
-            "version": "1.3",
+            "version": "1.4.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/slimphp/Slim-Http.git",
-                "reference": "9542edbe469b7c0f3084c2467efea972387f5beb"
+                "reference": "a8def7b8e9eabd0cdc21654ad4a82606942e066a"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/slimphp/Slim-Http/zipball/9542edbe469b7c0f3084c2467efea972387f5beb",
-                "reference": "9542edbe469b7c0f3084c2467efea972387f5beb",
+                "url": "https://api.github.com/repos/slimphp/Slim-Http/zipball/a8def7b8e9eabd0cdc21654ad4a82606942e066a",
+                "reference": "a8def7b8e9eabd0cdc21654ad4a82606942e066a",
                 "shasum": ""
             },
             "require": {
@@ -4891,18 +4948,19 @@
                 "ext-json": "*",
                 "ext-libxml": "*",
                 "ext-simplexml": "*",
-                "php": "^7.4 || ^8.0",
+                "php": "^8.0",
                 "psr/http-factory": "^1.0",
-                "psr/http-message": "^1.0"
+                "psr/http-message": "^1.1 || ^2.0"
             },
             "require-dev": {
-                "adriansuter/php-autoload-override": "^1.3",
-                "laminas/laminas-diactoros": "^2.17",
-                "nyholm/psr7": "^1.5",
-                "php-http/psr7-integration-tests": "dev-master",
-                "phpstan/phpstan": "^1.8",
-                "phpunit/phpunit": "^9.5",
-                "squizlabs/php_codesniffer": "^3.7"
+                "adriansuter/php-autoload-override": "^1.4",
+                "doctrine/instantiator": "^1.3.1",
+                "laminas/laminas-diactoros": "^3.1.0",
+                "nyholm/psr7": "^1.8.1",
+                "php-http/psr7-integration-tests": "^1.3.0",
+                "phpstan/phpstan": "^1.10",
+                "phpunit/phpunit": "^9.6",
+                "squizlabs/php_codesniffer": "^3.9"
             },
             "type": "library",
             "autoload": {
@@ -4945,9 +5003,9 @@
             ],
             "support": {
                 "issues": "https://github.com/slimphp/Slim-Http/issues",
-                "source": "https://github.com/slimphp/Slim-Http/tree/1.3"
+                "source": "https://github.com/slimphp/Slim-Http/tree/1.4.0"
             },
-            "time": "2022-09-14T15:45:07+00:00"
+            "time": "2024-06-24T18:27:41+00:00"
         },
         {
             "name": "slim/slim",
@@ -5137,16 +5195,16 @@
         },
         {
             "name": "srmklive/paypal",
-            "version": "3.0.31",
+            "version": "3.0.32",
             "source": {
                 "type": "git",
                 "url": "https://github.com/srmklive/laravel-paypal.git",
-                "reference": "378ac23b264c02481d15ece97a041520fc0814da"
+                "reference": "031d69d7c99f9ef0874a34cb85326ede28cd7aed"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/srmklive/laravel-paypal/zipball/378ac23b264c02481d15ece97a041520fc0814da",
-                "reference": "378ac23b264c02481d15ece97a041520fc0814da",
+                "url": "https://api.github.com/repos/srmklive/laravel-paypal/zipball/031d69d7c99f9ef0874a34cb85326ede28cd7aed",
+                "reference": "031d69d7c99f9ef0874a34cb85326ede28cd7aed",
                 "shasum": ""
             },
             "require": {
@@ -5197,9 +5255,9 @@
             ],
             "support": {
                 "issues": "https://github.com/srmklive/laravel-paypal/issues",
-                "source": "https://github.com/srmklive/laravel-paypal/tree/3.0.31"
+                "source": "https://github.com/srmklive/laravel-paypal/tree/3.0.32"
             },
-            "time": "2024-05-29T11:03:10+00:00"
+            "time": "2024-06-24T14:34:51+00:00"
         },
         {
             "name": "starkbank/ecdsa",

+ 18 - 0
config/settings.json

@@ -530,6 +530,24 @@
         "default": "",
         "mark": "AlibabaCloud DM From Alias"
     },
+    {
+        "item": "resend_api_key",
+        "value": "",
+        "class": "email",
+        "is_public": 0,
+        "type": "string",
+        "default": "",
+        "mark": "Resend API Key"
+    },
+    {
+        "item": "resend_from",
+        "value": "",
+        "class": "email",
+        "is_public": 0,
+        "type": "string",
+        "default": "",
+        "mark": "Resend From"
+    },
     {
         "item": "email_verify_code_ttl",
         "value": "3600",

+ 25 - 0
resources/views/tabler/admin/setting/email.tpl

@@ -57,6 +57,9 @@
                                 <li class="nav-item">
                                     <a href="#alibabacloud" class="nav-link" data-bs-toggle="tab">AlibabaCloud DM</a>
                                 </li>
+                                <li class="nav-item">
+                                    <a href="#resend" class="nav-link" data-bs-toggle="tab">Resend</a>
+                                </li>
                             </ul>
                         </div>
                         <div class="card-body">
@@ -100,6 +103,10 @@
                                                             {if $settings['email_driver'] === "alibabacloud"}selected{/if}>
                                                         AlibabaCloud DM
                                                     </option>
+                                                    <option value="resend"
+                                                            {if $settings['email_driver'] === "resend"}selected{/if}>
+                                                        Resend
+                                                    </option>
                                                 </select>
                                             </div>
                                         </div>
@@ -416,6 +423,24 @@
                                         </div>
                                     </div>
                                 </div>
+                                <div class="tab-pane" id="resend">
+                                    <div class="card-body">
+                                        <div class="form-group mb-3 row">
+                                            <label class="form-label col-3 col-form-label">Api Key</label>
+                                            <div class="col">
+                                                <input id="resend_api_key" type="text" class="form-control"
+                                                       value="{$settings['resend_api_key']}">
+                                            </div>
+                                        </div>
+                                        <div class="form-group mb-3 row">
+                                            <label class="form-label col-3 col-form-label">From</label>
+                                            <div class="col">
+                                                <input id="resend_from" type="text" class="form-control"
+                                                       value="{$settings['resend_from']}">
+                                            </div>
+                                        </div>
+                                    </div>
+                                </div>
                             </div>
                         </div>
                     </div>

+ 6 - 2
src/Services/Mail.php

@@ -10,11 +10,13 @@ use App\Services\Mail\Mailchimp;
 use App\Services\Mail\Mailgun;
 use App\Services\Mail\NullMail;
 use App\Services\Mail\Postal;
+use App\Services\Mail\Resend;
 use App\Services\Mail\SendGrid;
 use App\Services\Mail\Ses;
 use App\Services\Mail\Smtp;
-use Exception;
 use Psr\Http\Client\ClientExceptionInterface;
+use SendGrid\Mail\TypeException;
+use Smarty\Exception;
 use Smarty\Smarty;
 
 /*
@@ -22,13 +24,14 @@ use Smarty\Smarty;
  */
 final class Mail
 {
-    public static function getClient(): AlibabaCloud|Mailchimp|Mailgun|NullMail|Postal|SendGrid|Ses|Smtp
+    public static function getClient(): AlibabaCloud|Mailchimp|Mailgun|NullMail|Postal|Resend|SendGrid|Ses|Smtp
     {
         return match (Config::obtain('email_driver')) {
             'alibabacloud' => new AlibabaCloud(),
             'mailchimp' => new Mailchimp(),
             'mailgun' => new Mailgun(),
             'postal' => new Postal(),
+            'resend' => new Resend(),
             'sendgrid' => new SendGrid(),
             'ses' => new Ses(),
             'smtp' => new Smtp(),
@@ -57,6 +60,7 @@ final class Mail
     /**
      * @throws Exception
      * @throws ClientExceptionInterface
+     * @throws TypeException
      */
     public static function send($to, $subject, $template, $array = []): void
     {

+ 31 - 0
src/Services/Mail/Resend.php

@@ -0,0 +1,31 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Services\Mail;
+
+use App\Models\Config;
+use Resend as RS;
+
+final class Resend extends Base
+{
+    private RS\Client $resend;
+    private string $from;
+
+    public function __construct()
+    {
+        $configs = Config::getClass('email');
+        $this->resend = RS::client($configs['resend_api_key']);
+        $this->from = $configs['resend_from'];
+    }
+
+    public function send($to, $subject, $body): void
+    {
+        $this->resend->emails->send([
+            'from' => $this->from,
+            'to' => [$to],
+            'subject' => $subject,
+            'html' => $body,
+        ]);
+    }
+}