lasthourcloud/app/Http/Livewire/Settings/Email.php

57 lines
2.2 KiB
PHP
Raw Normal View History

2023-06-06 13:30:33 +00:00
<?php
namespace App\Http\Livewire\Settings;
use App\Models\InstanceSettings;
2023-06-12 10:00:01 +00:00
use App\Notifications\TransactionalEmails\TestEmail;
2023-06-06 15:50:13 +00:00
use Illuminate\Support\Facades\Notification;
2023-06-06 13:30:33 +00:00
use Livewire\Component;
class Email extends Component
{
public InstanceSettings $settings;
protected $rules = [
2023-06-13 08:51:58 +00:00
'settings.extra_attributes.smtp_active' => 'nullable|boolean',
2023-06-06 15:50:13 +00:00
'settings.extra_attributes.smtp_host' => 'required',
'settings.extra_attributes.smtp_port' => 'required|numeric',
'settings.extra_attributes.smtp_encryption' => 'nullable',
'settings.extra_attributes.smtp_username' => 'nullable',
'settings.extra_attributes.smtp_password' => 'nullable',
'settings.extra_attributes.smtp_timeout' => 'nullable',
'settings.extra_attributes.smtp_test_recipients' => 'nullable',
'settings.extra_attributes.smtp_from_address' => 'required|email',
'settings.extra_attributes.smtp_from_name' => 'required',
2023-06-06 13:30:33 +00:00
];
2023-06-13 08:51:58 +00:00
protected $validationAttributes = [
'settings.extra_attributes.smtp_from_address' => 'From Address',
'settings.extra_attributes.smtp_from_name' => 'From Name',
'settings.extra_attributes.smtp_recipients' => 'Recipients',
'settings.extra_attributes.smtp_host' => 'Host',
'settings.extra_attributes.smtp_port' => 'Port',
'settings.extra_attributes.smtp_encryption' => 'Encryption',
'settings.extra_attributes.smtp_username' => 'Username',
'settings.extra_attributes.smtp_password' => 'Password',
'settings.extra_attributes.smtp_test_recipients' => 'Test Recipients',
];
public function instantSave()
{
try {
$this->submit();
} catch (\Exception $e) {
$this->settings->extra_attributes->smtp_active = false;
$this->validate();
}
}
2023-06-06 13:30:33 +00:00
public function test_email()
{
2023-06-12 10:00:01 +00:00
Notification::send($this->settings, new TestEmail);
2023-06-06 13:30:33 +00:00
}
public function submit()
{
$this->validate();
2023-06-06 15:50:13 +00:00
$this->settings->extra_attributes->smtp_test_recipients = str_replace(' ', '', $this->settings->extra_attributes->smtp_test_recipients);
2023-06-06 13:30:33 +00:00
$this->settings->save();
}
}