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-20 17:08:43 +00:00
|
|
|
'settings.smtp.enabled' => 'nullable|boolean',
|
|
|
|
'settings.smtp.host' => 'required',
|
|
|
|
'settings.smtp.port' => 'required|numeric',
|
|
|
|
'settings.smtp.encryption' => 'nullable',
|
|
|
|
'settings.smtp.username' => 'nullable',
|
|
|
|
'settings.smtp.password' => 'nullable',
|
|
|
|
'settings.smtp.timeout' => 'nullable',
|
|
|
|
'settings.smtp.test_recipients' => 'nullable',
|
|
|
|
'settings.smtp.from_address' => 'required|email',
|
|
|
|
'settings.smtp.from_name' => 'required',
|
2023-06-06 13:30:33 +00:00
|
|
|
];
|
2023-06-13 08:51:58 +00:00
|
|
|
protected $validationAttributes = [
|
2023-06-20 17:08:43 +00:00
|
|
|
'settings.smtp.from_address' => 'From Address',
|
|
|
|
'settings.smtp.from_name' => 'From Name',
|
|
|
|
'settings.smtp.recipients' => 'Recipients',
|
|
|
|
'settings.smtp.host' => 'Host',
|
|
|
|
'settings.smtp.port' => 'Port',
|
|
|
|
'settings.smtp.encryption' => 'Encryption',
|
|
|
|
'settings.smtp.username' => 'Username',
|
|
|
|
'settings.smtp.password' => 'Password',
|
|
|
|
'settings.smtp.test_recipients' => 'Test Recipients',
|
2023-06-13 08:51:58 +00:00
|
|
|
];
|
|
|
|
public function instantSave()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->submit();
|
|
|
|
} catch (\Exception $e) {
|
2023-06-20 17:08:43 +00:00
|
|
|
$this->settings->smtp->enabled = false;
|
2023-06-13 08:51:58 +00:00
|
|
|
$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-19 08:58:00 +00:00
|
|
|
$this->emit('success', 'Test email sent.');
|
2023-06-06 13:30:33 +00:00
|
|
|
}
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
2023-06-20 17:08:43 +00:00
|
|
|
$this->settings->smtp->test_recipients = str_replace(' ', '', $this->settings->smtp->test_recipients);
|
2023-06-06 13:30:33 +00:00
|
|
|
$this->settings->save();
|
|
|
|
}
|
|
|
|
}
|