diff --git a/app/Helpers/Mail/GmailTransport.php b/app/Helpers/Mail/GmailTransport.php index fd2e7b66f1..be7e29df67 100644 --- a/app/Helpers/Mail/GmailTransport.php +++ b/app/Helpers/Mail/GmailTransport.php @@ -28,28 +28,27 @@ class GmailTransport extends Transport */ protected $gmail; - /** - * The GMail OAuth Token. - * @var string token - */ - protected $token; - /** * Create a new Gmail transport instance. * * @param Mail $gmail * @param string $token */ - public function __construct(Mail $gmail, string $token) + public function __construct(Mail $gmail) { $this->gmail = $gmail; - $this->token = $token; } public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) { /*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}"); $this->beforeSendPerformed($message); diff --git a/app/Helpers/Mail/GmailTransportManager.php b/app/Helpers/Mail/GmailTransportManager.php index efb1b2682c..268d3e8d58 100644 --- a/app/Helpers/Mail/GmailTransportManager.php +++ b/app/Helpers/Mail/GmailTransportManager.php @@ -1,5 +1,13 @@ app['config']->get('services.gmail.token', []); - $token = config('services.gmail.token'); - - $mail = new Mail; - - return new GmailTransport($mail, $token); + return new GmailTransport(new Mail); } } \ No newline at end of file diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 2e19f2b6f3..b643055807 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -84,6 +84,7 @@ 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'); /* Inject custom translations if any exist */ Lang::replace(Ninja::transformTranslations($this->nmo->settings)); @@ -120,15 +121,24 @@ class NinjaMailerJob implements ShouldQueue * just for this request. */ - config(['mail.driver' => 'gmail']); - config(['services.gmail.token' => $user->oauth_user_token->access_token]); - config(['mail.from.address' => $user->email]); - config(['mail.from.name' => $user->present()->name()]); + // config(['mail.driver' => 'gmail']); + // config(['services.gmail.token' => $user->oauth_user_token->access_token]); + // config(['mail.from.address' => $user->email]); + // 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)