mirror of
https://github.com/cedar2025/Xboard.git
synced 2025-02-02 07:28:13 -05:00
feat: add postal mail driver
This commit is contained in:
parent
53efe20a86
commit
6507d7888d
@ -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),
|
||||
|
@ -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' => '',
|
||||
|
@ -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,20 +38,26 @@ 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')));
|
||||
} 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 {
|
||||
switch ($driver) {
|
||||
case 'SMTP':
|
||||
Mail::send(
|
||||
$params['template_name'],
|
||||
$params['template_value'],
|
||||
@ -57,6 +65,22 @@ class SendEmailJob implements ShouldQueue
|
||||
$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();
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user