diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index e1cd61f3a032..76f137cc8a7c 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -793,9 +793,8 @@ class InvoiceController extends BaseController $contact = $invitation->contact; $invoice = $invitation->invoice; - $file = $invoice->service()->getInvoicePdf($contact); - - return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);; + $file = $invoice->pdf_file_path($invitation); + return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); } diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index acb6e44ed860..dc8d4d6ed2cd 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -59,6 +59,8 @@ class NinjaMailerJob implements ShouldQueue public $company; + private $mailer; + public function __construct(NinjaMailerObject $nmo, bool $override = false) { @@ -108,7 +110,8 @@ class NinjaMailerJob implements ShouldQueue try { nlog("trying to send to {$this->nmo->to_user->email} ". now()->toDateTimeString()); - Mail::to($this->nmo->to_user->email) + Mail::mailer($this->mailer) + ->to($this->nmo->to_user->email) ->send($this->nmo->mailable); LightLogs::create(new EmailSuccess($this->nmo->company->company_key)) @@ -151,18 +154,19 @@ class NinjaMailerJob implements ShouldQueue { /* Singletons need to be rebooted each time just in case our Locale is changing*/ App::forgetInstance('translator'); - App::forgetInstance('mail.manager'); //singletons must be destroyed! - App::forgetInstance('mailer'); - App::forgetInstance('laravelgmail'); + // App::forgetInstance('mail.manager'); //singletons must be destroyed! + // App::forgetInstance('mailer'); + // App::forgetInstance('laravelgmail'); $t = app('translator'); /* Inject custom translations if any exist */ $t->replace(Ninja::transformTranslations($this->nmo->settings)); switch ($this->nmo->settings->email_sending_method) { case 'default': - //config(['mail.driver' => config('mail.default')]); + $this->mailer = config('mail.default'); break; case 'gmail': + $this->mailer = 'gmail'; $this->setGmailMailer(); break; default: @@ -204,8 +208,8 @@ class NinjaMailerJob implements ShouldQueue * just for this request. */ - config(['mail.driver' => 'gmail']); - (new MailServiceProvider(app()))->register(); + // config(['mail.driver' => 'gmail']); + // (new MailServiceProvider(app()))->register(); $token = $user->oauth_user_token->access_token; diff --git a/app/Providers/MailCssInlinerServiceProvider.php b/app/Providers/MailCssInlinerServiceProvider.php index bdf47d34d5e5..ae0fa532bfae 100644 --- a/app/Providers/MailCssInlinerServiceProvider.php +++ b/app/Providers/MailCssInlinerServiceProvider.php @@ -1,4 +1,13 @@ app->afterResolving('mail.manager', function (MailManager $mailManager) { - // $mailManager->getSwiftMailer()->registerPlugin($this->app->make(CssInlinerPlugin::class)); - // return $mailManager; - // }); + $this->app->afterResolving('mail.manager', function (MailManager $mailManager) { + $mailManager->getSwiftMailer()->registerPlugin($this->app->make(CssInlinerPlugin::class)); + return $mailManager; + }); } } diff --git a/app/Providers/MailServiceProvider.php b/app/Providers/MailServiceProvider.php index f44dfd5cf7c4..ee41c57ccf9f 100644 --- a/app/Providers/MailServiceProvider.php +++ b/app/Providers/MailServiceProvider.php @@ -1,4 +1,13 @@ app->singleton('mail.manager', function($app) { return new GmailTransportManager($app); }); @@ -32,7 +42,7 @@ class MailServiceProvider extends MailProvider return $app->make('mail.manager')->mailer(); }); - $this->app['mail.manager']->extend('postmark', function () { + $this->app['mail.manager']->extend('cocopostmark', function () { return new PostmarkTransport( $this->guzzle(config('postmark.guzzle', [])), @@ -41,10 +51,6 @@ class MailServiceProvider extends MailProvider }); - $this->app->afterResolving('mail.manager', function (GmailTransportManager $mailManager) { - $mailManager->getSwiftMailer()->registerPlugin($this->app->make(CssInlinerPlugin::class)); - return $mailManager; - }); } protected function guzzle(array $config): HttpClient diff --git a/config/mail.php b/config/mail.php index 20d5582eb7eb..88b35739aa46 100644 --- a/config/mail.php +++ b/config/mail.php @@ -73,6 +73,9 @@ return [ 'gmail' => [ 'transport' => 'gmail', ], + 'cocopostmark' => [ + 'transport' => 'cocopostmark', + ], ],