Updates for outbound email reply to addresses

This commit is contained in:
David Bomba 2024-01-23 19:16:52 +11:00
parent 339c9d549a
commit 728d013b92
3 changed files with 23 additions and 12 deletions

View File

@ -51,10 +51,6 @@ class NinjaMailerJob implements ShouldQueue
public $deleteWhenMissingModels = true; public $deleteWhenMissingModels = true;
public $nmo;
public $override;
/** @var null|\App\Models\Company $company **/ /** @var null|\App\Models\Company $company **/
public ?Company $company; public ?Company $company;
@ -67,11 +63,8 @@ class NinjaMailerJob implements ShouldQueue
protected $client_mailgun_domain = false; 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() public function backoff()
@ -106,7 +99,10 @@ class NinjaMailerJob implements ShouldQueue
} }
$this->nmo->mailable->replyTo($this->nmo->settings->reply_to_email, $reply_to_name); $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()); $this->nmo->mailable->replyTo($this->company->owner()->email, $this->company->owner()->present()->name());
} }

View File

@ -16,6 +16,8 @@ namespace App\Jobs\Mail;
*/ */
class NinjaMailerObject class NinjaMailerObject
{ {
/* @var Illuminate\Mail\Mailable */
public $mailable; public $mailable;
/* @var Company $company */ /* @var Company $company */
@ -32,7 +34,7 @@ class NinjaMailerObject
/* Variable for cascading notifications */ /* Variable for cascading notifications */
public $entity_string = false; 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 $invitation = false;
public $template = false; public $template = false;

View File

@ -208,9 +208,22 @@ class EmailDefaults
*/ */
private function setReplyTo(): self 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)]); $this->email->email_object->reply_to = array_merge($this->email->email_object->reply_to, [new Address($reply_to_email, $reply_to_name)]);