Created new Mail Queuer to take advantage of OAUTH2 for M365 and Google Workspaces not enabled by default

This commit is contained in:
johnnyq
2025-09-16 15:43:54 -04:00
parent 0379143829
commit c769bbc405
2 changed files with 339 additions and 20 deletions

View File

@@ -7,13 +7,10 @@ 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) {
@@ -691,23 +688,6 @@ 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)
{