diff --git a/app/Http/Controllers/V1/Admin/ConfigController.php b/app/Http/Controllers/V1/Admin/ConfigController.php index b84d5fb..738c7d5 100755 --- a/app/Http/Controllers/V1/Admin/ConfigController.php +++ b/app/Http/Controllers/V1/Admin/ConfigController.php @@ -128,7 +128,9 @@ class ConfigController extends Controller 'email_username' => admin_setting('email_username'), 'email_password' => admin_setting('email_password'), 'email_encryption' => admin_setting('email_encryption'), - 'email_from_address' => admin_setting('email_from_address') + 'email_from_address' => admin_setting('email_from_address'), + 'email_postal_host' => admin_setting('email_postal_host'), + 'email_postal_key' => admin_setting('email_postal_key'), ], 'telegram' => [ 'telegram_bot_enable' => admin_setting('telegram_bot_enable', 0), @@ -188,7 +190,7 @@ class ConfigController extends Controller ); } } - + Cache::forget('admin_settings'); // \Artisan::call('horizon:terminate'); //重启队列使配置生效 return $this->success(true); diff --git a/app/Http/Requests/Admin/ConfigSave.php b/app/Http/Requests/Admin/ConfigSave.php index c5dd5fc..1efe80c 100755 --- a/app/Http/Requests/Admin/ConfigSave.php +++ b/app/Http/Requests/Admin/ConfigSave.php @@ -62,6 +62,8 @@ class ConfigSave extends FormRequest 'email_password' => '', 'email_encryption' => '', 'email_from_address' => '', + 'email_postal_host' => '', + 'email_postal_key' => '', // telegram 'telegram_bot_enable' => 'in:0,1', 'telegram_bot_token' => '', diff --git a/app/Jobs/SendEmailJob.php b/app/Jobs/SendEmailJob.php index 9a9f174..a66e0cf 100644 --- a/app/Jobs/SendEmailJob.php +++ b/app/Jobs/SendEmailJob.php @@ -10,6 +10,8 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Mail; use App\Models\MailLog; +use Postal\Client; +use Postal\Send\Message; class SendEmailJob implements ShouldQueue { @@ -36,27 +38,49 @@ class SendEmailJob implements ShouldQueue */ public function handle() { + $driver = ""; if (admin_setting('email_host')) { + $driver = "SMTP"; Config::set('mail.host', admin_setting('email_host', config('mail.host'))); Config::set('mail.port', admin_setting('email_port', config('mail.port'))); Config::set('mail.encryption', admin_setting('email_encryption', config('mail.encryption'))); Config::set('mail.username', admin_setting('email_username', config('mail.username'))); Config::set('mail.password', admin_setting('email_password', config('mail.password'))); - Config::set('mail.from.address', admin_setting('email_from_address', config('mail.from.address'))); - Config::set('mail.from.name', admin_setting('app_name', 'XBoard')); + } elseif (admin_setting('email_postal_host')) { + $driver = "Postal"; } + Config::set('mail.from.address', admin_setting('email_from_address', config('mail.from.address'))); + Config::set('mail.from.name', admin_setting('app_name', 'XBoard')); $params = $this->params; $email = $params['email']; $subject = $params['subject']; $params['template_name'] = 'mail.' . admin_setting('email_template', 'default') . '.' . $params['template_name']; try { - Mail::send( - $params['template_name'], - $params['template_value'], - function ($message) use ($email, $subject) { - $message->to($email)->subject($subject); - } - ); + switch ($driver) { + case 'SMTP': + Mail::send( + $params['template_name'], + $params['template_value'], + function ($message) use ($email, $subject) { + $message->to($email)->subject($subject); + } + ); + break; + case 'Postal': + $senderName = Config::get('mail.from.name'); + $senderAddress = Config::get('mail.from.address'); + $client = new Client(admin_config('email_postal_host'), admin_config('email_postal_key')); + $message = new Message(); + $message->to($email); + $message->from("$senderName <$senderAddress>"); + $message->sender($senderAddress); + $message->subject($subject); + $message->htmlBody(view($params['template_name'], $params['template_value'])->render()); + $client->send->message($message); + break; + default: + break; + } } catch (\Exception $e) { $error = $e->getMessage(); } diff --git a/composer.json b/composer.json index 66a96ae..71e41e0 100755 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "nunomaduro/collision": "^7.10", "paragonie/sodium_compat": "^1.20", "php-curl-class/php-curl-class": "^8.6", + "postal/postal": "^2.0", "spatie/db-dumper": "^3.4", "stripe/stripe-php": "^7.36.1", "symfony/http-client": "^6.4",