From 728d013b92adafcb40028b209230c9e41e34a8c7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 23 Jan 2024 19:16:52 +1100 Subject: [PATCH] Updates for outbound email reply to addresses --- app/Jobs/Mail/NinjaMailerJob.php | 14 +++++--------- app/Jobs/Mail/NinjaMailerObject.php | 4 +++- app/Services/Email/EmailDefaults.php | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 49f4f0b28bd5..073c3aa1d1f7 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -51,10 +51,6 @@ class NinjaMailerJob implements ShouldQueue public $deleteWhenMissingModels = true; - public $nmo; - - public $override; - /** @var null|\App\Models\Company $company **/ public ?Company $company; @@ -67,11 +63,8 @@ class NinjaMailerJob implements ShouldQueue protected $client_mailgun_domain = false; - public function __construct(NinjaMailerObject $nmo, bool $override = false) + public function __construct(public NinjaMailerObject $nmo, public bool $override = false) { - $this->nmo = $nmo; - - $this->override = $override; } public function backoff() @@ -106,7 +99,10 @@ class NinjaMailerJob implements ShouldQueue } $this->nmo->mailable->replyTo($this->nmo->settings->reply_to_email, $reply_to_name); - } else { + }elseif(isset($this->nmo->invitation->user)){ + $this->nmo->mailable->replyTo($this->nmo->invitation->user->email, $this->nmo->invitation->user->present()->name()); + } + else { $this->nmo->mailable->replyTo($this->company->owner()->email, $this->company->owner()->present()->name()); } diff --git a/app/Jobs/Mail/NinjaMailerObject.php b/app/Jobs/Mail/NinjaMailerObject.php index df33c35c2a11..f2cf0f646111 100644 --- a/app/Jobs/Mail/NinjaMailerObject.php +++ b/app/Jobs/Mail/NinjaMailerObject.php @@ -16,6 +16,8 @@ namespace App\Jobs\Mail; */ class NinjaMailerObject { + + /* @var Illuminate\Mail\Mailable */ public $mailable; /* @var Company $company */ @@ -32,7 +34,7 @@ class NinjaMailerObject /* Variable for cascading notifications */ public $entity_string = false; - /* @var bool | App\Models\InvoiceInvitation | App\Models\QuoteInvitation | App\Models\CreditInvitation | App\Models\RecurringInvoiceInvitation | App\Models\PurchaseOrderInvitation $invitation*/ + /* @var App\Models\InvoiceInvitation | App\Models\QuoteInvitation | App\Models\CreditInvitation | App\Models\RecurringInvoiceInvitation | App\Models\PurchaseOrderInvitation | \bool $invitation*/ public $invitation = false; public $template = false; diff --git a/app/Services/Email/EmailDefaults.php b/app/Services/Email/EmailDefaults.php index c01d5380941c..6598bac40d9f 100644 --- a/app/Services/Email/EmailDefaults.php +++ b/app/Services/Email/EmailDefaults.php @@ -208,9 +208,22 @@ class EmailDefaults */ private function setReplyTo(): self { - $reply_to_email = str_contains($this->email->email_object->settings->reply_to_email, "@") ? $this->email->email_object->settings->reply_to_email : $this->email->company->owner()->email; + $reply_to_email = $this->email->company->owner()->email; + $reply_to_name = $this->email->company->owner()->present()->name(); - $reply_to_name = strlen($this->email->email_object->settings->reply_to_name) > 3 ? $this->email->email_object->settings->reply_to_name : $this->email->company->owner()->present()->name(); + if(str_contains($this->email->email_object->settings->reply_to_email, "@")){ + $reply_to_email = $this->email->email_object->settings->reply_to_email; + } + elseif(isset($this->email->email_object->invitation->user)) { + $reply_to_email = $this->email->email_object->invitation->user->email; + } + + if(strlen($this->email->email_object->settings->reply_to_name) > 3) { + $reply_to_name =$this->email->email_object->settings->reply_to_name; + } + elseif(isset($this->email->email_object->invitation->user)) { + $reply_to_name = $this->email->email_object->invitation->user->present()->name(); + } $this->email->email_object->reply_to = array_merge($this->email->email_object->reply_to, [new Address($reply_to_email, $reply_to_name)]);