updates
This commit is contained in:
@@ -12,11 +12,10 @@ class EmailChannel
|
||||
{
|
||||
$this->bootConfigs($notifiable);
|
||||
|
||||
if ($notification instanceof \App\Notifications\TestNotification) {
|
||||
$is_test_notification = $notification instanceof \App\Notifications\TestNotification;
|
||||
|
||||
if ($is_test_notification) {
|
||||
$bcc = $notifiable->routeNotificationForEmail('smtp_test_recipients');
|
||||
if (count($bcc) === 0) {
|
||||
$bcc = $notifiable->routeNotificationForEmail();
|
||||
}
|
||||
} else {
|
||||
$bcc = $notifiable->routeNotificationForEmail();
|
||||
}
|
||||
|
||||
51
app/Notifications/Channels/TransactionalEmailChannel.php
Normal file
51
app/Notifications/Channels/TransactionalEmailChannel.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Channels;
|
||||
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\User;
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class TransactionalEmailChannel
|
||||
{
|
||||
public function send(User $notifiable, Notification $notification): void
|
||||
{
|
||||
$email = $notifiable->email;
|
||||
if (!$email) {
|
||||
return;
|
||||
}
|
||||
$settings = InstanceSettings::get();
|
||||
$this->bootConfigs($settings);
|
||||
$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')
|
||||
)
|
||||
->to($email)
|
||||
->subject($mailMessage->subject)
|
||||
->html((string)$mailMessage->render())
|
||||
);
|
||||
}
|
||||
|
||||
private function bootConfigs(InstanceSettings $settings): void
|
||||
{
|
||||
config()->set('mail.default', 'smtp');
|
||||
config()->set('mail.mailers.smtp', [
|
||||
"transport" => "smtp",
|
||||
"host" => $settings->extra_attributes?->get('smtp_host'),
|
||||
"port" => $settings->extra_attributes?->get('smtp_port'),
|
||||
"encryption" => $settings->extra_attributes?->get('smtp_encryption'),
|
||||
"username" => $settings->extra_attributes?->get('smtp_username'),
|
||||
"password" => $settings->extra_attributes?->get('smtp_password'),
|
||||
"timeout" => $settings->extra_attributes?->get('smtp_timeout'),
|
||||
"local_domain" => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -12,20 +12,6 @@ use Illuminate\Notifications\Notification;
|
||||
class TestNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
$channels = [];
|
||||
@@ -33,11 +19,7 @@ class TestNotification extends Notification implements ShouldQueue
|
||||
$notifiable->extra_attributes?->get('discord_active') && $channels[] = DiscordChannel::class;
|
||||
return $channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->subject('Coolify Test Notification')
|
||||
@@ -45,20 +27,8 @@ class TestNotification extends Notification implements ShouldQueue
|
||||
->line('You have successfully received a test Email notification from Coolify. 🥳');
|
||||
}
|
||||
|
||||
public function toDiscord(object $notifiable): string
|
||||
public function toDiscord(): string
|
||||
{
|
||||
return 'You have successfully received a test Discord notification from Coolify. 🥳 [Go to your dashboard](' . url('/') . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Notifications\Channels\EmailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class TestTransactionEmail extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
$channels = [];
|
||||
$notifiable->extra_attributes?->get('smtp_host') && $channels[] = EmailChannel::class;
|
||||
return $channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$mail = new MailMessage();
|
||||
$mail->subject('Coolify Test Notification');
|
||||
$mail->view('emails.test-email');
|
||||
return $mail;
|
||||
}
|
||||
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\TransactionalEmails;
|
||||
|
||||
use App\Models\Team;
|
||||
use App\Models\TeamInvitation;
|
||||
use App\Models\User;
|
||||
use App\Notifications\Channels\TransactionalEmailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class InvitationLinkEmail extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public function via()
|
||||
{
|
||||
return [TransactionalEmailChannel::class];
|
||||
}
|
||||
|
||||
public function toMail(User $user): MailMessage
|
||||
{
|
||||
$invitation = TeamInvitation::whereEmail($user->email)->first();
|
||||
$invitation_team = Team::find($invitation->team->id);
|
||||
|
||||
$mail = new MailMessage();
|
||||
$mail->subject('Invitation for ' . $invitation_team->name);
|
||||
$mail->view('emails.invitation-link', [
|
||||
'team' => $invitation_team->name,
|
||||
'email' => $user->email,
|
||||
'invitation_link' => $invitation->link,
|
||||
]);
|
||||
return $mail;
|
||||
}
|
||||
}
|
||||
26
app/Notifications/TransactionalEmails/TestEmail.php
Normal file
26
app/Notifications/TransactionalEmails/TestEmail.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\TransactionalEmails;
|
||||
|
||||
use App\Notifications\Channels\EmailChannel;
|
||||
use App\Notifications\Channels\TransactionalEmailChannel;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class TestEmail extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
public function via(): array
|
||||
{
|
||||
return [EmailChannel::class];
|
||||
}
|
||||
public function toMail(): MailMessage
|
||||
{
|
||||
$mail = new MailMessage();
|
||||
$mail->subject('Coolify Test Notification');
|
||||
$mail->view('emails.test');
|
||||
return $mail;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user