Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
534f22a0df
5 changed files with 67 additions and 11 deletions
|
|
@ -88,8 +88,7 @@ public function send(SendsEmail $notifiable, Notification $notification): void
|
||||||
);
|
);
|
||||||
$mailer = new Mailer($transport);
|
$mailer = new Mailer($transport);
|
||||||
|
|
||||||
$email = (new Email)
|
$email = mail_from_email(new Email, $settings)
|
||||||
->from(mail_from_address($settings))
|
|
||||||
->to(...$recipients)
|
->to(...$recipients)
|
||||||
->subject($mailMessage->subject)
|
->subject($mailMessage->subject)
|
||||||
->html((string) $mailMessage->render());
|
->html((string) $mailMessage->render());
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,10 @@ public function send(User $notifiable, Notification $notification): void
|
||||||
}
|
}
|
||||||
$this->bootConfigs();
|
$this->bootConfigs();
|
||||||
$mailMessage = $notification->toMail($notifiable);
|
$mailMessage = $notification->toMail($notifiable);
|
||||||
$from = mail_from_identity($settings);
|
|
||||||
Mail::send(
|
Mail::send(
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
fn (Message $message) => $message
|
fn (Message $message) => mail_from_message($message, $settings)
|
||||||
->from($from['address'], $from['name'])
|
|
||||||
->to($email)
|
->to($email)
|
||||||
->subject($mailMessage->subject)
|
->subject($mailMessage->subject)
|
||||||
->html((string) $mailMessage->render())
|
->html((string) $mailMessage->render())
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ protected function buildMailMessage($url)
|
||||||
$from = mail_from_identity($this->settings);
|
$from = mail_from_identity($this->settings);
|
||||||
$mail = new MailMessage;
|
$mail = new MailMessage;
|
||||||
$mail->from($from['address'], $from['name']);
|
$mail->from($from['address'], $from['name']);
|
||||||
|
$mail->withSymfonyMessage(fn ($message) => prevent_mail_from_header_folding($message, $this->settings));
|
||||||
$mail->subject('Coolify: Reset Password');
|
$mail->subject('Coolify: Reset Password');
|
||||||
$mail->view('emails.reset-password', ['url' => $url, 'count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]);
|
$mail->view('emails.reset-password', ['url' => $url, 'count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
use Illuminate\Notifications\Messages\MailMessage;
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Symfony\Component\Mime\Address;
|
use Symfony\Component\Mime\Address;
|
||||||
|
use Symfony\Component\Mime\Email;
|
||||||
|
|
||||||
function is_transactional_emails_enabled(): bool
|
function is_transactional_emails_enabled(): bool
|
||||||
{
|
{
|
||||||
|
|
@ -45,6 +46,32 @@ function mail_from_formatted(object $settings): string
|
||||||
return mail_from_address($settings)->toString();
|
return mail_from_address($settings)->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mail_from_email(Email $email, object $settings): Email
|
||||||
|
{
|
||||||
|
$email->from(mail_from_address($settings));
|
||||||
|
prevent_mail_from_header_folding($email, $settings);
|
||||||
|
|
||||||
|
return $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mail_from_message(Message $message, object $settings): Message
|
||||||
|
{
|
||||||
|
$identity = mail_from_identity($settings);
|
||||||
|
$message->from($identity['address'], $identity['name']);
|
||||||
|
prevent_mail_from_header_folding($message->getSymfonyMessage(), $settings);
|
||||||
|
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
function prevent_mail_from_header_folding(Email $email, object $settings): void
|
||||||
|
{
|
||||||
|
if (strtolower(trim((string) ($settings->smtp_host ?? ''))) !== 'smtp.protonmail.ch') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$email->getHeaders()->get('From')?->setMaxLineLength(998);
|
||||||
|
}
|
||||||
|
|
||||||
function send_internal_notification(string $message): void
|
function send_internal_notification(string $message): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
@ -61,14 +88,11 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null
|
||||||
if (blank($type)) {
|
if (blank($type)) {
|
||||||
throw new Exception('No email settings found.');
|
throw new Exception('No email settings found.');
|
||||||
}
|
}
|
||||||
$from = mail_from_identity($settings);
|
|
||||||
|
|
||||||
if ($cc) {
|
if ($cc) {
|
||||||
Mail::send(
|
Mail::send(
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
fn (Message $message) => $message
|
fn (Message $message) => mail_from_message($message, $settings)
|
||||||
->from($from['address'], $from['name'])
|
|
||||||
->to($email)
|
->to($email)
|
||||||
->replyTo($email)
|
->replyTo($email)
|
||||||
->cc($cc)
|
->cc($cc)
|
||||||
|
|
@ -79,8 +103,7 @@ function send_user_an_email(MailMessage $mail, string $email, ?string $cc = null
|
||||||
Mail::send(
|
Mail::send(
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
fn (Message $message) => $message
|
fn (Message $message) => mail_from_message($message, $settings)
|
||||||
->from($from['address'], $from['name'])
|
|
||||||
->to($email)
|
->to($email)
|
||||||
->subject($mail->subject)
|
->subject($mail->subject)
|
||||||
->html((string) $mail->render())
|
->html((string) $mail->render())
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Mail\Message;
|
||||||
use Symfony\Component\Mime\Address;
|
use Symfony\Component\Mime\Address;
|
||||||
|
use Symfony\Component\Mime\Email;
|
||||||
|
|
||||||
it('uses the configured transactional from name and address', function () {
|
it('uses the configured transactional from name and address', function () {
|
||||||
$identity = mail_from_identity((object) [
|
$identity = mail_from_identity((object) [
|
||||||
|
|
@ -33,6 +35,39 @@
|
||||||
expect($formattedAddress)->toBe('"Coolify" <admin@example.com>');
|
expect($formattedAddress)->toBe('"Coolify" <admin@example.com>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keeps the smtp from name and address on the same header line', function () {
|
||||||
|
$email = mail_from_email(new Email, (object) [
|
||||||
|
'smtp_host' => 'smtp.protonmail.ch',
|
||||||
|
'smtp_from_address' => 'contact@advanceddigitalmarketingltda.com',
|
||||||
|
'smtp_from_name' => 'Advanced Digital Marketing LTDA',
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect($email->getHeaders()->get('From')?->toString())
|
||||||
|
->toBe('From: Advanced Digital Marketing LTDA <contact@advanceddigitalmarketingltda.com>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the Laravel mail from name and address on the same header line', function () {
|
||||||
|
$message = mail_from_message(new Message(new Email), (object) [
|
||||||
|
'smtp_host' => 'smtp.protonmail.ch',
|
||||||
|
'smtp_from_address' => 'contact@advanceddigitalmarketingltda.com',
|
||||||
|
'smtp_from_name' => 'Advanced Digital Marketing LTDA',
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect($message->getSymfonyMessage()->getHeaders()->get('From')?->toString())
|
||||||
|
->toBe('From: Advanced Digital Marketing LTDA <contact@advanceddigitalmarketingltda.com>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps Symfony header folding for other smtp providers', function () {
|
||||||
|
$email = mail_from_email(new Email, (object) [
|
||||||
|
'smtp_host' => 'smtp.example.com',
|
||||||
|
'smtp_from_address' => 'contact@advanceddigitalmarketingltda.com',
|
||||||
|
'smtp_from_name' => 'Advanced Digital Marketing LTDA',
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect($email->getHeaders()->get('From')?->toString())
|
||||||
|
->toBe("From: Advanced Digital Marketing LTDA\r\n <contact@advanceddigitalmarketingltda.com>");
|
||||||
|
});
|
||||||
|
|
||||||
it('treats a blank from name as missing instead of sending an unnamed address', function () {
|
it('treats a blank from name as missing instead of sending an unnamed address', function () {
|
||||||
$identity = mail_from_identity((object) [
|
$identity = mail_from_identity((object) [
|
||||||
'smtp_from_address' => 'admin@example.com',
|
'smtp_from_address' => 'admin@example.com',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue