diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index c21b36059ced..77ec1d573169 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -258,9 +258,11 @@ class NinjaMailerJob implements ShouldQueue switch ($this->nmo->settings->email_sending_method) { case 'default': $this->mailer = config('mail.default'); + // $this->setHostedMailgunMailer(); //should only be activated if hosted platform needs to fall back to mailgun break; case 'mailgun': $this->mailer = 'mailgun'; + $this->setHostedMailgunMailer(); break; case 'gmail': $this->mailer = 'gmail'; @@ -368,6 +370,21 @@ class NinjaMailerJob implements ShouldQueue return $user; } + private function setHostedMailgunMailer() + { + + if (property_exists($this->nmo->settings, 'email_from_name') && strlen($this->nmo->settings->email_from_name) > 1) { + $email_from_name = $this->nmo->settings->email_from_name; + } else { + $email_from_name = $this->company->present()->name(); + } + + $this->nmo + ->mailable + ->from(config('services.mailgun.from.address'), $email_from_name); + + } + /** * Configures Mailgun using client supplied secret * as the Mailer diff --git a/app/Services/Email/Email.php b/app/Services/Email/Email.php index aa09fec8d95e..e1cbb99ef3b2 100644 --- a/app/Services/Email/Email.php +++ b/app/Services/Email/Email.php @@ -463,6 +463,21 @@ class Email implements ShouldQueue return false; } + private function setHostedMailgunMailer() + { + + if (property_exists($this->email_object->settings, 'email_from_name') && strlen($this->email_object->settings->email_from_name) > 1) { + $email_from_name = $this->email_object->settings->email_from_name; + } else { + $email_from_name = $this->company->present()->name(); + } + + $this->mailable + ->from(config('services.mailgun.from.address'), $email_from_name); + + } + + /** * Sets the mail driver to use and applies any specific configuration * the the mailable @@ -472,9 +487,11 @@ class Email implements ShouldQueue switch ($this->email_object->settings->email_sending_method) { case 'default': $this->mailer = config('mail.default'); + // $this->setHostedMailgunMailer(); //should only be activated if hosted platform needs to fall back to mailgun break; case 'mailgun': $this->mailer = 'mailgun'; + $this->setHostedMailgunMailer(); break; case 'gmail': $this->mailer = 'gmail'; diff --git a/config/services.php b/config/services.php index 0b933611ac62..d73f3555c01d 100644 --- a/config/services.php +++ b/config/services.php @@ -24,6 +24,10 @@ return [ 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 'webhook_signing_key' => env('MAILGUN_WEBHOOK_SIGNING_KEY', ''), 'scheme' => 'https', + 'from' => [ + 'address' => env('MAILGUN_FROM_ADDRESS', ''), + 'name' => env('MAILGUN_FROM_NAME', ''), + ], ], 'postmark' => [