mirror of
https://github.com/itflow-org/itflow
synced 2026-11-21 03:47:25 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user