mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-14 23:22:52 +01:00
Merge pull request #4921 from turbo124/v5-develop
Fixes for switching mailers are runtime when using queues
This commit is contained in:
commit
0e9e5eb744
@ -28,28 +28,27 @@ class GmailTransport extends Transport
|
|||||||
*/
|
*/
|
||||||
protected $gmail;
|
protected $gmail;
|
||||||
|
|
||||||
/**
|
|
||||||
* The GMail OAuth Token.
|
|
||||||
* @var string token
|
|
||||||
*/
|
|
||||||
protected $token;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Gmail transport instance.
|
* Create a new Gmail transport instance.
|
||||||
*
|
*
|
||||||
* @param Mail $gmail
|
* @param Mail $gmail
|
||||||
* @param string $token
|
* @param string $token
|
||||||
*/
|
*/
|
||||||
public function __construct(Mail $gmail, string $token)
|
public function __construct(Mail $gmail)
|
||||||
{
|
{
|
||||||
$this->gmail = $gmail;
|
$this->gmail = $gmail;
|
||||||
$this->token = $token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
|
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
|
||||||
{
|
{
|
||||||
/*We should nest the token in the message and then discard it as needed*/
|
/*We should nest the token in the message and then discard it as needed*/
|
||||||
|
|
||||||
|
$token = $message->get('GmailToken');
|
||||||
|
|
||||||
|
nlog("gmail transporter token = {$token}");
|
||||||
|
|
||||||
|
$message->remove('GmailToken');
|
||||||
|
|
||||||
nlog("inside gmail sender with token {$this->token}");
|
nlog("inside gmail sender with token {$this->token}");
|
||||||
|
|
||||||
$this->beforeSendPerformed($message);
|
$this->beforeSendPerformed($message);
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
<?php
|
<?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://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
namespace App\Helpers\Mail;
|
namespace App\Helpers\Mail;
|
||||||
|
|
||||||
use Illuminate\Mail\MailManager;
|
use Illuminate\Mail\MailManager;
|
||||||
@ -12,12 +20,6 @@ class GmailTransportManager extends MailManager
|
|||||||
{
|
{
|
||||||
protected function createGmailTransport()
|
protected function createGmailTransport()
|
||||||
{
|
{
|
||||||
info("booting gmail transport");
|
return new GmailTransport(new Mail);
|
||||||
// $token = $this->app['config']->get('services.gmail.token', []);
|
|
||||||
$token = config('services.gmail.token');
|
|
||||||
|
|
||||||
$mail = new Mail;
|
|
||||||
|
|
||||||
return new GmailTransport($mail, $token);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -84,6 +84,7 @@ class NinjaMailerJob implements ShouldQueue
|
|||||||
/* Singletons need to be rebooted each time just in case our Locale is changing*/
|
/* Singletons need to be rebooted each time just in case our Locale is changing*/
|
||||||
App::forgetInstance('translator');
|
App::forgetInstance('translator');
|
||||||
App::forgetInstance('mail.manager'); //singletons must be destroyed!
|
App::forgetInstance('mail.manager'); //singletons must be destroyed!
|
||||||
|
App::forgetInstance('mailer');
|
||||||
|
|
||||||
/* Inject custom translations if any exist */
|
/* Inject custom translations if any exist */
|
||||||
Lang::replace(Ninja::transformTranslations($this->nmo->settings));
|
Lang::replace(Ninja::transformTranslations($this->nmo->settings));
|
||||||
@ -120,15 +121,24 @@ class NinjaMailerJob implements ShouldQueue
|
|||||||
* just for this request.
|
* just for this request.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
config(['mail.driver' => 'gmail']);
|
// config(['mail.driver' => 'gmail']);
|
||||||
config(['services.gmail.token' => $user->oauth_user_token->access_token]);
|
// config(['services.gmail.token' => $user->oauth_user_token->access_token]);
|
||||||
config(['mail.from.address' => $user->email]);
|
// config(['mail.from.address' => $user->email]);
|
||||||
config(['mail.from.name' => $user->present()->name()]);
|
// config(['mail.from.name' => $user->present()->name()]);
|
||||||
|
|
||||||
(new MailServiceProvider(app()))->register();
|
// (new MailServiceProvider(app()))->register();
|
||||||
|
|
||||||
|
// nlog("after registering mail service provider");
|
||||||
|
// nlog(config('services.gmail.token'));
|
||||||
|
|
||||||
|
$token = $user->oauth_user_token->access_token;
|
||||||
|
$this->nmo
|
||||||
|
->mailable
|
||||||
|
->from($user->email, $user->present()->name())
|
||||||
|
->withSwiftMessage(function ($message) use($token) {
|
||||||
|
$message->getHeaders()->addTextHeader('GmailToken', $token);
|
||||||
|
});
|
||||||
|
|
||||||
nlog("after registering mail service provider");
|
|
||||||
nlog(config('services.gmail.token'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function logMailError($errors, $recipient_object)
|
private function logMailError($errors, $recipient_object)
|
||||||
|
Loading…
Reference in New Issue
Block a user