This commit is contained in:
Andras Bacsai
2023-06-20 19:08:43 +02:00
parent f648ab49f7
commit 9f0ca1cc2e
19 changed files with 226 additions and 197 deletions

View File

@@ -12,7 +12,7 @@ class EmailChannel
{
$this->bootConfigs($notifiable);
$bcc = $notifiable->routeNotificationForEmail('smtp_test_recipients');
$bcc = $notifiable->routeNotificationForEmail('test_recipients');
if (count($bcc) === 0) {
if ($notifiable instanceof \App\Models\Team) {
$bcc = $notifiable->members()->pluck('email')->toArray();
@@ -24,8 +24,8 @@ class EmailChannel
[],
fn (Message $message) => $message
->from(
$notifiable->extra_attributes?->get('smtp_from_address'),
$notifiable->extra_attributes?->get('smtp_from_name')
data_get($notifiable, 'smtp.from_address'),
data_get($notifiable, 'smtp.from_name'),
)
->bcc($bcc)
->subject($mailMessage->subject)
@@ -38,12 +38,12 @@ class EmailChannel
config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [
"transport" => "smtp",
"host" => $notifiable->extra_attributes?->get('smtp_host'),
"port" => $notifiable->extra_attributes?->get('smtp_port'),
"encryption" => $notifiable->extra_attributes?->get('smtp_encryption'),
"username" => $notifiable->extra_attributes?->get('smtp_username'),
"password" => $notifiable->extra_attributes?->get('smtp_password'),
"timeout" => $notifiable->extra_attributes?->get('smtp_timeout'),
"host" => data_get($notifiable, 'smtp.host'),
"port" => data_get($notifiable, 'smtp.port'),
"encryption" => data_get($notifiable, 'smtp.encryption'),
"username" => data_get($notifiable, 'smtp.username'),
"password" => data_get($notifiable, 'smtp.password'),
"timeout" => data_get($notifiable, 'smtp.timeout'),
"local_domain" => null,
]);
}

View File

@@ -13,23 +13,22 @@ class TransactionalEmailChannel
public function send(User $notifiable, Notification $notification): void
{
$settings = InstanceSettings::get();
if ($settings->extra_attributes?->get('smtp_enabled') !== true) {
if (data_get($settings, 'smtp.enabled') !== true) {
return;
}
$email = $notifiable->email;
if (!$email) {
return;
}
$this->bootConfigs($settings);
$this->bootConfigs();
$mailMessage = $notification->toMail($notifiable);
Mail::send(
[],
[],
fn (Message $message) => $message
->from(
$settings->extra_attributes?->get('smtp_from_address'),
$settings->extra_attributes?->get('smtp_from_name')
data_get($settings, 'smtp.from_address'),
data_get($settings, 'smtp.from_name')
)
->to($email)
->subject($mailMessage->subject)
@@ -37,7 +36,7 @@ class TransactionalEmailChannel
);
}
private function bootConfigs(InstanceSettings $settings): void
private function bootConfigs(): void
{
set_transanctional_email_settings();
}