mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
feat: add postal mail driver
This commit is contained in:
parent
7d36d47ca1
commit
ae9685d554
@ -61,6 +61,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' => '',
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\MailLog;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@ -9,15 +11,17 @@ use Illuminate\Queue\InteractsWithQueue;
|
||||
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
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $params;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 10;
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -36,20 +40,26 @@ class SendEmailJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$driver = "";
|
||||
if (config('v2board.email_host')) {
|
||||
$driver = "SMTP";
|
||||
Config::set('mail.host', config('v2board.email_host', env('mail.host')));
|
||||
Config::set('mail.port', config('v2board.email_port', env('mail.port')));
|
||||
Config::set('mail.encryption', config('v2board.email_encryption', env('mail.encryption')));
|
||||
Config::set('mail.username', config('v2board.email_username', env('mail.username')));
|
||||
Config::set('mail.password', config('v2board.email_password', env('mail.password')));
|
||||
} elseif (config('v2board.email_postal_host')) {
|
||||
$driver = "Postal";
|
||||
}
|
||||
Config::set('mail.from.address', config('v2board.email_from_address', env('mail.from.address')));
|
||||
Config::set('mail.from.name', config('v2board.app_name', 'V2Board'));
|
||||
}
|
||||
$params = $this->params;
|
||||
$email = $params['email'];
|
||||
$subject = $params['subject'];
|
||||
$params['template_name'] = 'mail.' . config('v2board.email_template', 'default') . '.' . $params['template_name'];
|
||||
try {
|
||||
switch ($driver) {
|
||||
case 'SMTP':
|
||||
Mail::send(
|
||||
$params['template_name'],
|
||||
$params['template_value'],
|
||||
@ -57,7 +67,23 @@ class SendEmailJob implements ShouldQueue
|
||||
$message->to($email)->subject($subject);
|
||||
}
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
break;
|
||||
case 'Postal':
|
||||
$senderName = Config::get('mail.from.name');
|
||||
$senderAddress = Config::get('mail.from.address');
|
||||
$client = new Client(config('v2board.email_postal_host'), config('v2board.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();
|
||||
}
|
||||
|
||||
@ -65,7 +91,7 @@ class SendEmailJob implements ShouldQueue
|
||||
'email' => $params['email'],
|
||||
'subject' => $params['subject'],
|
||||
'template_name' => $params['template_name'],
|
||||
'error' => isset($error) ? $error : NULL
|
||||
'error' => $error ?? NULL
|
||||
];
|
||||
|
||||
MailLog::create($log);
|
||||
|
@ -68,7 +68,9 @@ class ConfigService {
|
||||
'email_username' => config('v2board.email_username'),
|
||||
'email_password' => config('v2board.email_password'),
|
||||
'email_encryption' => config('v2board.email_encryption'),
|
||||
'email_from_address' => config('v2board.email_from_address')
|
||||
'email_from_address' => config('v2board.email_from_address'),
|
||||
'email_postal_host' => config('v2board.email_postal_host'),
|
||||
'email_postal_key' => config('v2board.email_postal_key'),
|
||||
],
|
||||
'telegram' => [
|
||||
'telegram_bot_enable' => config('v2board.telegram_bot_enable', 0),
|
||||
|
@ -22,6 +22,7 @@
|
||||
"laravel/tinker": "^2.5",
|
||||
"linfo/linfo": "^4.0",
|
||||
"php-curl-class/php-curl-class": "^8.6",
|
||||
"postal/postal": "^2.0",
|
||||
"stripe/stripe-php": "^7.36.1",
|
||||
"symfony/yaml": "^4.3",
|
||||
"paragonie/sodium_compat": "^1.20"
|
||||
|
Loading…
Reference in New Issue
Block a user