1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Fixes for mail drivers

This commit is contained in:
David Bomba 2021-06-17 17:48:23 +10:00
parent c33a9d0ae5
commit 8c06eaa5ae
4 changed files with 38 additions and 16 deletions

View File

@ -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;

View File

@ -1,4 +1,13 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Providers;
@ -33,9 +42,9 @@ class MailCssInlinerServiceProvider extends ServiceProvider
return new CssInlinerPlugin([]);
});
// $this->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;
});
}
}

View File

@ -1,4 +1,13 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Providers;
@ -24,6 +33,7 @@ class MailServiceProvider extends MailProvider
protected function registerIlluminateMailer()
{
$this->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

View File

@ -73,6 +73,9 @@ return [
'gmail' => [
'transport' => 'gmail',
],
'cocopostmark' => [
'transport' => 'cocopostmark',
],
],