a lot hehe
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Channels;
|
||||
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class CoolifyEmailChannel
|
||||
{
|
||||
/**
|
||||
* Send the given notification.
|
||||
*/
|
||||
public function send(SendsCoolifyEmail $notifiable, Notification $notification): void
|
||||
{
|
||||
$this->bootConfigs($notifiable);
|
||||
$bcc = $notifiable->routeNotificationForCoolifyEmail();
|
||||
$mailMessage = $notification->toMail($notifiable);
|
||||
|
||||
Mail::send([], [], fn(Message $message) => $message
|
||||
->from(
|
||||
$notifiable->extra_attributes?->get('from_address'),
|
||||
$notifiable->extra_attributes?->get('from_name')
|
||||
)
|
||||
->bcc($bcc)
|
||||
->subject($mailMessage->subject)
|
||||
->html((string)$mailMessage->render())
|
||||
);
|
||||
}
|
||||
|
||||
private function bootConfigs($notifiable): void
|
||||
{
|
||||
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'),
|
||||
"local_domain" => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,7 @@ class DiscordChannel
|
||||
public function send(SendsDiscord $notifiable, Notification $notification): void
|
||||
{
|
||||
$message = $notification->toDiscord($notifiable);
|
||||
|
||||
$webhookUrl = $notifiable->routeNotificationForDiscord();
|
||||
|
||||
dispatch(new SendMessageToDiscordJob($message, $webhookUrl));
|
||||
}
|
||||
}
|
||||
|
||||
56
app/Notifications/Channels/EmailChannel.php
Normal file
56
app/Notifications/Channels/EmailChannel.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Channels;
|
||||
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class EmailChannel
|
||||
{
|
||||
/**
|
||||
* Send the given notification.
|
||||
*/
|
||||
public function send(SendsEmail $notifiable, Notification $notification): void
|
||||
{
|
||||
$this->bootConfigs($notifiable);
|
||||
if ($notification instanceof \App\Notifications\TestNotification) {
|
||||
$bcc = $notifiable->routeNotificationForEmail('test_address');
|
||||
if (count($bcc) === 1) {
|
||||
$bcc = $notifiable->routeNotificationForEmail();
|
||||
}
|
||||
} else {
|
||||
$bcc = $notifiable->routeNotificationForEmail();
|
||||
}
|
||||
$mailMessage = $notification->toMail($notifiable);
|
||||
|
||||
Mail::send(
|
||||
[],
|
||||
[],
|
||||
fn (Message $message) => $message
|
||||
->from(
|
||||
$notifiable->smtp_attributes?->get('from_address'),
|
||||
$notifiable->smtp_attributes?->get('from_name')
|
||||
)
|
||||
->cc($bcc)
|
||||
->bcc($bcc)
|
||||
->subject($mailMessage->subject)
|
||||
->html((string)$mailMessage->render())
|
||||
);
|
||||
}
|
||||
|
||||
private function bootConfigs($notifiable): void
|
||||
{
|
||||
config()->set('mail.default', 'smtp');
|
||||
config()->set('mail.mailers.smtp', [
|
||||
"transport" => "smtp",
|
||||
"host" => $notifiable->smtp_attributes?->get('smtp_host'),
|
||||
"port" => $notifiable->smtp_attributes?->get('smtp_port'),
|
||||
"encryption" => $notifiable->smtp_attributes?->get('smtp_encryption'),
|
||||
"username" => $notifiable->smtp_attributes?->get('smtp_username'),
|
||||
"password" => $notifiable->smtp_attributes?->get('smtp_password'),
|
||||
"timeout" => $notifiable->smtp_attributes?->get('smtp_timeout'),
|
||||
"local_domain" => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Channels;
|
||||
|
||||
interface SendsCoolifyEmail
|
||||
{
|
||||
public function routeNotificationForCoolifyEmail();
|
||||
}
|
||||
8
app/Notifications/Channels/SendsEmail.php
Normal file
8
app/Notifications/Channels/SendsEmail.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Channels;
|
||||
|
||||
interface SendsEmail
|
||||
{
|
||||
public function routeNotificationForEmail();
|
||||
}
|
||||
Reference in New Issue
Block a user