From 8510ee822426a7187965581304a4ad570ab88c29 Mon Sep 17 00:00:00 2001 From: FreeScout Date: Wed, 12 Jun 2024 20:45:58 -0700 Subject: [PATCH] Microsoft Exchange oAuth for SMTP - closes #4072 --- app/Misc/Mail.php | 4 ++-- resources/views/mailboxes/connection.blade.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Misc/Mail.php b/app/Misc/Mail.php index 6ae5c618b..bb3516222 100644 --- a/app/Misc/Mail.php +++ b/app/Misc/Mail.php @@ -104,7 +104,7 @@ public static function setMailDriver($mailbox = null, $user_from = null, $conver $oauth = $mailbox->oauthEnabled(); // Refresh Access Token. - if ($oauth) { + if ($oauth && !strstr($mailbox->out_username, '@')) { if ((strtotime($mailbox->oauthGetParam('issued_on')) + (int)$mailbox->oauthGetParam('expires_in')) < time()) { // Try to get an access token (using the authorization code grant) $token_data = \MailHelper::oauthGetAccessToken(\MailHelper::OAUTH_PROVIDER_MICROSOFT, [ @@ -134,7 +134,7 @@ public static function setMailDriver($mailbox = null, $user_from = null, $conver if ($mailbox->out_method == Mailbox::OUT_METHOD_SMTP) { \Config::set('mail.host', $mailbox->out_server); \Config::set('mail.port', $mailbox->out_port); - if ($oauth) { + if ($oauth && !strstr($mailbox->out_username, '@')) { \Config::set('mail.auth_mode', 'XOAUTH2'); \Config::set('mail.username', $mailbox->email); \Config::set('mail.password', $mailbox->oauthGetParam('a_token')); diff --git a/resources/views/mailboxes/connection.blade.php b/resources/views/mailboxes/connection.blade.php index 3546280cb..bd8db1780 100644 --- a/resources/views/mailboxes/connection.blade.php +++ b/resources/views/mailboxes/connection.blade.php @@ -88,7 +88,7 @@
- out_method == App\Mailbox::OUT_METHOD_SMTP) @endif autofocus {{-- This added to prevent autocomplete in Chrome --}}autocomplete="new-password" @if ($mailbox->oauthEnabled()) readonly @endif> + out_method == App\Mailbox::OUT_METHOD_SMTP) @endif autofocus {{-- This added to prevent autocomplete in Chrome --}}autocomplete="new-password" @if ($mailbox->oauthEnabled() && strstr($mailbox->out_username, '@')) readonly @endif> @include('partials/field_error', ['field'=>'out_username'])
@@ -97,7 +97,7 @@
- out_method == App\Mailbox::OUT_METHOD_SMTP) @endif autofocus {{-- This added to prevent autocomplete in Chrome --}}autocomplete="new-password" @if ($mailbox->oauthEnabled()) readonly @endif> + out_method == App\Mailbox::OUT_METHOD_SMTP) @endif autofocus {{-- This added to prevent autocomplete in Chrome --}}autocomplete="new-password" @if ($mailbox->oauthEnabled() && strstr($mailbox->out_username, '@')) readonly @endif>

oauthGetParam('provider') == \MailHelper::OAUTH_PROVIDER_MICROSOFT) class="text-success" @endif>Microsoft Exchange