mirror of
https://github.com/coollabsio/coolify.git
synced 2026-08-24 10:05:47 -05:00
fix(email): apply configured sender identity (#11393)
This commit is contained in:
@@ -5,6 +5,7 @@ use App\Notifications\Internal\GeneralNotification;
|
||||
use Illuminate\Mail\Message;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Symfony\Component\Mime\Address;
|
||||
|
||||
function is_transactional_emails_enabled(): bool
|
||||
{
|
||||
@@ -13,6 +14,37 @@ function is_transactional_emails_enabled(): bool
|
||||
return $settings->smtp_enabled || $settings->resend_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{address: string, name: string}
|
||||
*/
|
||||
function mail_from_identity(object $settings): array
|
||||
{
|
||||
if (blank($settings->smtp_from_address ?? null)) {
|
||||
throw new InvalidArgumentException('Transactional email sender address is not configured.');
|
||||
}
|
||||
|
||||
$address = (string) $settings->smtp_from_address;
|
||||
|
||||
$name = trim((string) ($settings->smtp_from_name ?? ''));
|
||||
|
||||
return [
|
||||
'address' => $address,
|
||||
'name' => $name !== '' ? $name : 'Coolify',
|
||||
];
|
||||
}
|
||||
|
||||
function mail_from_address(object $settings): Address
|
||||
{
|
||||
$identity = mail_from_identity($settings);
|
||||
|
||||
return new Address($identity['address'], $identity['name']);
|
||||
}
|
||||
|
||||
function mail_from_formatted(object $settings): string
|
||||
{
|
||||
return mail_from_address($settings)->toString();
|
||||
}
|
||||
|
||||
function send_internal_notification(string $message): void
|
||||
{
|
||||
try {
|
||||
@@ -29,11 +61,14 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null
|
||||
if (blank($type)) {
|
||||
throw new Exception('No email settings found.');
|
||||
}
|
||||
$from = mail_from_identity($settings);
|
||||
|
||||
if ($cc) {
|
||||
Mail::send(
|
||||
[],
|
||||
[],
|
||||
fn (Message $message) => $message
|
||||
->from($from['address'], $from['name'])
|
||||
->to($email)
|
||||
->replyTo($email)
|
||||
->cc($cc)
|
||||
@@ -45,6 +80,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null
|
||||
[],
|
||||
[],
|
||||
fn (Message $message) => $message
|
||||
->from($from['address'], $from['name'])
|
||||
->to($email)
|
||||
->subject($mail->subject)
|
||||
->html((string) $mail->render())
|
||||
|
||||
Reference in New Issue
Block a user