Mail: Microsoft 365 sends email and reads the support mailbox through Microsoft Graph when the app on the OAuth tab has Mail.Send or Mail.ReadWrite, so the mailbox needs no SMTP AUTH, and SMTP or IMAP stay in use for whatever it lacks; new functions/mail_graph.php with mailGraphToken caching the Graph token and its scopes and keeping the rotated refresh token, mailGraphSend sending the finished MIME or a draft with uploaded attachments past 3 MB, and functions/mail_graph_mailbox.php standing in for ImapEngine in the email parser; the OAuth tab says which way email goes, Test IMAP and Test OAuth Token Refresh cover Graph, the Exchange token renewals now name their scope, database 3.9.2 adds three settings columns, 26.11.9 changelog entries

This commit is contained in:
johnnyq
2026-11-17 23:49:02 -05:00
parent 5aa7280c9b
commit a31471eff3
11 changed files with 769 additions and 14 deletions

View File

@@ -163,6 +163,7 @@ function refreshMailOauthAccessToken(string $provider, string $oauth_client_id,
'client_secret' => $oauth_client_secret,
'refresh_token' => $oauth_refresh_token,
'grant_type' => 'refresh_token',
'scope' => MAIL_MICROSOFT_EXCHANGE_SCOPE, // the refresh token may last have been renewed for Graph (functions/mail_graph.php)
]);
}
}
@@ -269,7 +270,11 @@ function sendQueueEmail(
$mail->SMTPSecure = $enc; // 'tls' | 'ssl'
}
if ($provider === 'google_oauth' || $provider === 'microsoft_oauth') {
// Microsoft 365 sends through Microsoft Graph when the app has Mail.Send - no SMTP sign-in then
// (functions/mail_graph.php). Microsoft refusing Graph stops this email with its reason.
$graph_token = $provider === 'microsoft_oauth' ? mailGraphToken('Mail.Send') : null;
if ($graph_token === null && ($provider === 'google_oauth' || $provider === 'microsoft_oauth')) {
// XOAUTH2
$mail->SMTPAuth = true;
$mail->AuthType = 'XOAUTH2';
@@ -355,6 +360,11 @@ function sendQueueEmail(
}
}
if ($graph_token !== null) {
mailGraphSend($mail, $graph_token);
return true;
}
try {
$mail->send();
} catch (Exception $e) {