From aa852930e67e612476d26963ae72780aae0eb9b3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 2 Dec 2020 14:08:35 +1100 Subject: [PATCH] refactor from email names to use config() values --- app/Jobs/Mail/BaseMailerJob.php | 2 ++ app/Jobs/Mail/EntityPaidMailer.php | 2 +- app/Jobs/Mail/EntitySentMailer.php | 2 +- app/Jobs/Mail/EntityViewedMailer.php | 2 +- app/Jobs/Mail/PaymentFailureMailer.php | 2 +- app/Jobs/Util/Import.php | 5 +++-- app/Mail/Admin/EntityNotificationMailer.php | 2 +- app/Mail/BouncedEmail.php | 4 ++-- app/Mail/DownloadInvoices.php | 18 ++++++++++-------- app/Mail/ExistingMigration.php | 4 +++- app/Mail/Invoices/InvoiceWasPaid.php | 2 +- app/Mail/MigrationCompleted.php | 5 +++-- app/Mail/MigrationFailed.php | 5 +++-- app/Mail/Quote/QuoteWasApproved.php | 2 +- app/Mail/SupportMessageSent.php | 2 +- app/Mail/TemplateEmail.php | 2 +- app/Mail/TestMailServer.php | 2 +- app/Mail/User/UserNotificationMailer.php | 2 +- config/ninja.php | 1 + 19 files changed, 38 insertions(+), 28 deletions(-) diff --git a/app/Jobs/Mail/BaseMailerJob.php b/app/Jobs/Mail/BaseMailerJob.php index cddb89bbb72c..d0649ba73fc7 100644 --- a/app/Jobs/Mail/BaseMailerJob.php +++ b/app/Jobs/Mail/BaseMailerJob.php @@ -77,6 +77,8 @@ class BaseMailerJob implements ShouldQueue Config::set('mail.driver', 'gmail'); Config::set('services.gmail.token', $user->oauth_user_token->access_token); + Config::set('mail.from.address', $user->email); + Config::set('mail.from.name', $user->present()->name()); (new MailServiceProvider(app()))->register(); } diff --git a/app/Jobs/Mail/EntityPaidMailer.php b/app/Jobs/Mail/EntityPaidMailer.php index a2ad45ed1494..01d8eb635f37 100644 --- a/app/Jobs/Mail/EntityPaidMailer.php +++ b/app/Jobs/Mail/EntityPaidMailer.php @@ -77,7 +77,7 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue try { $mail_obj = (new EntityPaidObject($this->payment))->build(); - $mail_obj->from = [$this->user->email, $this->user->present()->name()]; + $mail_obj->from = [config('mail.from.address'), config('mail.from.name')]; //send email Mail::to($this->user->email) diff --git a/app/Jobs/Mail/EntitySentMailer.php b/app/Jobs/Mail/EntitySentMailer.php index 175159b7669b..4ee370f43cf7 100644 --- a/app/Jobs/Mail/EntitySentMailer.php +++ b/app/Jobs/Mail/EntitySentMailer.php @@ -81,7 +81,7 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue $this->setMailDriver(); $mail_obj = (new EntitySentObject($this->invitation, $this->entity_type))->build(); - $mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()]; + $mail_obj->from = [config('mail.from.address'), config('mail.from.name')]; try { Mail::to($this->user->email) diff --git a/app/Jobs/Mail/EntityViewedMailer.php b/app/Jobs/Mail/EntityViewedMailer.php index 1bd22f5e1ddd..416250264034 100644 --- a/app/Jobs/Mail/EntityViewedMailer.php +++ b/app/Jobs/Mail/EntityViewedMailer.php @@ -81,7 +81,7 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue $this->setMailDriver(); $mail_obj = (new EntityViewedObject($this->invitation, $this->entity_type))->build(); - $mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()]; + $mail_obj->from = [config('mail.from.address'), config('mail.from.name')]; //send email try { diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index 2f59c93f3384..73f570729cfd 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -91,7 +91,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue unset($methods[$key]); $mail_obj = (new PaymentFailureObject($this->client, $this->message, $this->amount, $this->company))->build(); - $mail_obj->from = [$this->company->owner()->email, $this->company->owner()->present()->name()]; + $mail_obj->from = [config('mail.from.address'), config('mail.from.name')]; //send email try { diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 54c5378c5efb..b3b30d3c724c 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -199,8 +199,9 @@ class Import implements ShouldQueue } $this->setInitialCompanyLedgerBalances(); - - Mail::to($this->user)->send(new MigrationCompleted()); + + Mail::to($this->user) + ->send(new MigrationCompleted()); /*After a migration first some basic jobs to ensure the system is up to date*/ VersionCheck::dispatch(); diff --git a/app/Mail/Admin/EntityNotificationMailer.php b/app/Mail/Admin/EntityNotificationMailer.php index 9f91d113672e..344e161d78e8 100644 --- a/app/Mail/Admin/EntityNotificationMailer.php +++ b/app/Mail/Admin/EntityNotificationMailer.php @@ -34,7 +34,7 @@ class EntityNotificationMailer extends Mailable */ public function build() { - return $this->from($this->mail_obj->from[0], $this->mail_obj->from[1]) + return $this->from(config('mail.from.address'), config('mail.from.name')) ->subject($this->mail_obj->subject) ->markdown($this->mail_obj->markdown, $this->mail_obj->data) ->withSwiftMessage(function ($message) { diff --git a/app/Mail/BouncedEmail.php b/app/Mail/BouncedEmail.php index ef7c59827eb9..7aaedccff532 100644 --- a/app/Mail/BouncedEmail.php +++ b/app/Mail/BouncedEmail.php @@ -43,9 +43,9 @@ class BouncedEmail extends Mailable implements ShouldQueue $entity_type = class_basename(lcfirst($this->invitation->getEntityType())); $subject = ctrans("texts.notification_{$entity_type}_bounced_subject", ['invoice' => $invoice->number]); - + return - $this->from($invitation->user->email) + $this->from(config('mail.from.name'), config('mail.from.address')) ->text() ->subject($subject); diff --git a/app/Mail/DownloadInvoices.php b/app/Mail/DownloadInvoices.php index 9d6720c89162..2c65d34ee125 100644 --- a/app/Mail/DownloadInvoices.php +++ b/app/Mail/DownloadInvoices.php @@ -30,13 +30,15 @@ class DownloadInvoices extends Mailable */ public function build() { - return $this->subject(ctrans('texts.download_files')) - ->markdown( - 'email.admin.download_files', - [ - 'url' => $this->file_path, - 'logo' => $this->company->present()->logo, - ] - ); + + return $this->from(config('mail.from.name'), config('mail.from.address')) + ->subject(ctrans('texts.download_files')) + ->markdown( + 'email.admin.download_files', + [ + 'url' => $this->file_path, + 'logo' => $this->company->present()->logo, + ] + ); } } diff --git a/app/Mail/ExistingMigration.php b/app/Mail/ExistingMigration.php index b9b657daa2f1..596947b7fcab 100644 --- a/app/Mail/ExistingMigration.php +++ b/app/Mail/ExistingMigration.php @@ -27,6 +27,8 @@ class ExistingMigration extends Mailable */ public function build() { - return $this->view('email.migration.existing'); + + return $this->from(config('mail.from.name'), config('mail.from.address')) + ->view('email.migration.existing'); } } diff --git a/app/Mail/Invoices/InvoiceWasPaid.php b/app/Mail/Invoices/InvoiceWasPaid.php index 72979b88a829..3dc64bf16f0f 100644 --- a/app/Mail/Invoices/InvoiceWasPaid.php +++ b/app/Mail/Invoices/InvoiceWasPaid.php @@ -27,6 +27,6 @@ class InvoiceWasPaid extends Mailable */ public function build() { - return $this->view('email.invoices.paid'); + return $this->from(config('mail.from.address'), config('mail.from.name'))->view('email.invoices.paid'); } } diff --git a/app/Mail/MigrationCompleted.php b/app/Mail/MigrationCompleted.php index 988b36c0f819..358a15a6c3bc 100644 --- a/app/Mail/MigrationCompleted.php +++ b/app/Mail/MigrationCompleted.php @@ -28,7 +28,8 @@ class MigrationCompleted extends Mailable public function build() { $data['settings'] = auth()->user()->company()->settings; - - return $this->view('email.migration.completed', $data); + + return $this->from(config('mail.from.name'), config('mail.from.address')) + ->view('email.migration.completed', $data); } } diff --git a/app/Mail/MigrationFailed.php b/app/Mail/MigrationFailed.php index 71bb53cfac9e..545736fd0bf3 100644 --- a/app/Mail/MigrationFailed.php +++ b/app/Mail/MigrationFailed.php @@ -31,7 +31,8 @@ class MigrationFailed extends Mailable */ public function build() { - return $this->from('noreply@invoiceninja.com') - ->view('email.migration.failed'); + + return $this->from(config('mail.from.name'), config('mail.from.address')) + ->view('email.migration.failed'); } } diff --git a/app/Mail/Quote/QuoteWasApproved.php b/app/Mail/Quote/QuoteWasApproved.php index dbe095b577af..a5b9a7348776 100644 --- a/app/Mail/Quote/QuoteWasApproved.php +++ b/app/Mail/Quote/QuoteWasApproved.php @@ -27,6 +27,6 @@ class QuoteWasApproved extends Mailable */ public function build() { - return $this->view('email.quotes.approved'); + return $this->from(config('mail.from.address'), config('mail.from.name'))->view('email.quotes.approved'); } } diff --git a/app/Mail/SupportMessageSent.php b/app/Mail/SupportMessageSent.php index cfecff8ce2c5..8c71d9fed9c4 100644 --- a/app/Mail/SupportMessageSent.php +++ b/app/Mail/SupportMessageSent.php @@ -59,7 +59,7 @@ class SupportMessageSent extends Mailable $subject = "Customer MSG {$user->present()->name} - [{$plan} - DB:{$company->db}]"; - return $this->from(config('mail.from.address')) //todo this needs to be fixed to handle the hosted version + return $this->from(config('mail.from.address'), config('mail.from.name')) //todo this needs to be fixed to handle the hosted version ->subject($subject) ->markdown('email.support.message', [ 'message' => $this->message, diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 464eac9ea25f..0154a12752ef 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -52,7 +52,7 @@ class TemplateEmail extends Mailable $company = $this->client->company; - $this->from($this->user->email, $this->user->present()->name()); + $this->from(config('mail.from.address'), config('mail.from.name')); if (strlen($settings->reply_to_email) > 1) { $this->replyTo($settings->reply_to_email, $settings->reply_to_email); diff --git a/app/Mail/TestMailServer.php b/app/Mail/TestMailServer.php index e392e121b334..ee1ebde3dd9d 100644 --- a/app/Mail/TestMailServer.php +++ b/app/Mail/TestMailServer.php @@ -36,7 +36,7 @@ class TestMailServer extends Mailable */ public function build() { - return $this->from($this->from_email) //todo this needs to be fixed to handle the hosted version + return $this->from(config('mail.from.address'), config('mail.from.name')) ->subject(ctrans('texts.email')) ->markdown('email.support.message', [ 'message' => $this->message, diff --git a/app/Mail/User/UserNotificationMailer.php b/app/Mail/User/UserNotificationMailer.php index 97a56513871b..4a55a368042f 100644 --- a/app/Mail/User/UserNotificationMailer.php +++ b/app/Mail/User/UserNotificationMailer.php @@ -34,7 +34,7 @@ class UserNotificationMailer extends Mailable */ public function build() { - return $this->from($this->mail_obj->from[0], $this->mail_obj->from[1]) //todo + return $this->from(config('mail.from.address'), config('mail.from.name')) ->subject($this->mail_obj->subject) ->markdown($this->mail_obj->markdown, $this->mail_obj->data) ->withSwiftMessage(function ($message) { diff --git a/config/ninja.php b/config/ninja.php index 53e91347349e..7276e438f2ea 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -23,6 +23,7 @@ return [ 'date_time_format' => 'Y-m-d H:i', 'daily_email_limit' => 300, 'error_email' => env('ERROR_EMAIL', ''), + 'mailer' => env('MAIL_MAILER',''), 'company_id' => 0, 'hash_salt' => env('HASH_SALT', ''), 'currency_converter_api_key' => env('OPENEXCHANGE_APP_ID', ''),