refactor(notifications): Improve transactional email settings handling
- Replace `! $type` checks with `blank($type)` for consistency - Modify email settings configuration to handle null/disabled states - Ensure proper fallback and configuration of email providers
This commit is contained in:
@@ -54,7 +54,7 @@ class Controller extends BaseController
|
|||||||
'email' => Str::lower($arrayOfRequest['email']),
|
'email' => Str::lower($arrayOfRequest['email']),
|
||||||
]);
|
]);
|
||||||
$type = set_transanctional_email_settings();
|
$type = set_transanctional_email_settings();
|
||||||
if (! $type) {
|
if (blank($type)) {
|
||||||
return response()->json(['message' => 'Transactional emails are not active'], 400);
|
return response()->json(['message' => 'Transactional emails are not active'], 400);
|
||||||
}
|
}
|
||||||
$request->validate([Fortify::email() => 'required|email']);
|
$request->validate([Fortify::email() => 'required|email']);
|
||||||
|
@@ -36,7 +36,7 @@ class Help extends Component
|
|||||||
$type = set_transanctional_email_settings($settings);
|
$type = set_transanctional_email_settings($settings);
|
||||||
|
|
||||||
// Sending feedback through Cloud API
|
// Sending feedback through Cloud API
|
||||||
if ($type === false) {
|
if (blank($type)) {
|
||||||
$url = 'https://app.coolify.io/api/feedback';
|
$url = 'https://app.coolify.io/api/feedback';
|
||||||
Http::post($url, [
|
Http::post($url, [
|
||||||
'content' => 'User: `'.auth()->user()?->email.'` with subject: `'.$this->subject.'` has the following problem: `'.$this->description.'`',
|
'content' => 'User: `'.auth()->user()?->email.'` with subject: `'.$this->subject.'` has the following problem: `'.$this->description.'`',
|
||||||
|
@@ -50,11 +50,9 @@ class EmailChannel
|
|||||||
|
|
||||||
if ($emailSettings->use_instance_email_settings) {
|
if ($emailSettings->use_instance_email_settings) {
|
||||||
$type = set_transanctional_email_settings();
|
$type = set_transanctional_email_settings();
|
||||||
if (! $type) {
|
if (blank($type)) {
|
||||||
throw new Exception('No email settings found.');
|
throw new Exception('No email settings found.');
|
||||||
}
|
}
|
||||||
config()->set('mail.default', $type);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ class TransactionalEmailChannel
|
|||||||
private function bootConfigs(): void
|
private function bootConfigs(): void
|
||||||
{
|
{
|
||||||
$type = set_transanctional_email_settings();
|
$type = set_transanctional_email_settings();
|
||||||
if (! $type) {
|
if (blank($type)) {
|
||||||
throw new Exception('No email settings found.');
|
throw new Exception('No email settings found.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Notifications\TransactionalEmails;
|
namespace App\Notifications\TransactionalEmails;
|
||||||
|
|
||||||
use App\Models\InstanceSettings;
|
use App\Models\InstanceSettings;
|
||||||
|
use Exception;
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
use Illuminate\Notifications\Notification;
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
@@ -35,8 +36,8 @@ class ResetPassword extends Notification
|
|||||||
public function via($notifiable)
|
public function via($notifiable)
|
||||||
{
|
{
|
||||||
$type = set_transanctional_email_settings();
|
$type = set_transanctional_email_settings();
|
||||||
if (! $type) {
|
if (blank($type)) {
|
||||||
throw new \Exception('No email settings found.');
|
throw new Exception('No email settings found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['mail'];
|
return ['mail'];
|
||||||
|
@@ -28,7 +28,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null
|
|||||||
{
|
{
|
||||||
$settings = instanceSettings();
|
$settings = instanceSettings();
|
||||||
$type = set_transanctional_email_settings($settings);
|
$type = set_transanctional_email_settings($settings);
|
||||||
if (! $type) {
|
if (blank($type)) {
|
||||||
throw new Exception('No email settings found.');
|
throw new Exception('No email settings found.');
|
||||||
}
|
}
|
||||||
if ($cc) {
|
if ($cc) {
|
||||||
@@ -54,15 +54,19 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_transanctional_email_settings(?InstanceSettings $settings = null): ?string //
|
function set_transanctional_email_settings(?InstanceSettings $settings = null): ?string // returns null|resend|smtp and defaults to array based on mail.php config
|
||||||
{
|
{
|
||||||
if (! $settings) {
|
if (! $settings) {
|
||||||
$settings = instanceSettings();
|
$settings = instanceSettings();
|
||||||
}
|
}
|
||||||
config()->set('mail.from.address', data_get($settings, 'smtp_from_address'));
|
if (! data_get($settings, 'smtp_enabled') && ! data_get($settings, 'resend_enabled')) {
|
||||||
config()->set('mail.from.name', data_get($settings, 'smtp_from_name'));
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (data_get($settings, 'resend_enabled')) {
|
if (data_get($settings, 'resend_enabled')) {
|
||||||
config()->set('mail.default', 'resend');
|
config()->set('mail.default', 'resend');
|
||||||
|
config()->set('mail.from.address', data_get($settings, 'smtp_from_address'));
|
||||||
|
config()->set('mail.from.name', data_get($settings, 'smtp_from_name'));
|
||||||
config()->set('resend.api_key', data_get($settings, 'resend_api_key'));
|
config()->set('resend.api_key', data_get($settings, 'resend_api_key'));
|
||||||
|
|
||||||
return 'resend';
|
return 'resend';
|
||||||
@@ -76,6 +80,8 @@ function set_transanctional_email_settings(?InstanceSettings $settings = null):
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (data_get($settings, 'smtp_enabled')) {
|
if (data_get($settings, 'smtp_enabled')) {
|
||||||
|
config()->set('mail.from.address', data_get($settings, 'smtp_from_address'));
|
||||||
|
config()->set('mail.from.name', data_get($settings, 'smtp_from_name'));
|
||||||
config()->set('mail.default', 'smtp');
|
config()->set('mail.default', 'smtp');
|
||||||
config()->set('mail.mailers.smtp', [
|
config()->set('mail.mailers.smtp', [
|
||||||
'transport' => 'smtp',
|
'transport' => 'smtp',
|
||||||
@@ -91,6 +97,4 @@ function set_transanctional_email_settings(?InstanceSettings $settings = null):
|
|||||||
|
|
||||||
return 'smtp';
|
return 'smtp';
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user