Added SMTP Provider and the ability to share OAUTH keys with IMAP for M365 Mail Auth

This commit is contained in:
johnnyq
2025-09-15 17:23:00 -04:00
parent 902323a75b
commit dc0715da57
7 changed files with 220 additions and 188 deletions

View File

@@ -7,10 +7,13 @@ DEFINE("WORDING_ROLECHECK_FAILED", "You are not permitted to do that!");
require_once "plugins/PHPMailer/src/Exception.php";
require_once "plugins/PHPMailer/src/PHPMailer.php";
require_once "plugins/PHPMailer/src/SMTP.php";
require_once "plugins/PHPMailer/src/OAuthTokenProvider.php";
require_once "plugins/PHPMailer/src/OAuth.php";
// Initiate PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\OAuthTokenProvider;
// Function to generate both crypto & URL safe random strings
function randomString($length = 16) {
@@ -688,6 +691,23 @@ function validateAccountantRole() {
}
}
/**
* Minimal token provider for PHPMailer XOAUTH2 without external deps.
*/
class StaticTokenProvider implements OAuthTokenProvider {
private $email;
private $accessToken;
public function __construct(string $email, string $accessToken) {
$this->email = $email;
$this->accessToken = $accessToken;
}
public function getOauth64(): string {
// XOAUTH2 SASL string: "user=<email>\x01auth=Bearer <token>\x01\x01"
$authString = "user={$this->email}\x01auth=Bearer {$this->accessToken}\x01\x01";
return base64_encode($authString);
}
}
// Send a single email to a single recipient
function sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port, $from_email, $from_name, $to_email, $to_name, $subject, $body, $ics_str)
{