-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Already having the token, send mail using ms office oauth2 authentication #2813
Comments
One problem with driving PHPMailer with an externally-generated access token is that the token expires very quickly. Using a refresh token (which MSFT expires after 90 days for most clients) is far more manageable. |
I already have a function that I call before using the token and that check the validity and eventually refresh it. I don't need PHPMailer to do it for me. Maybe that's also the case for other users... |
Well... you could of course create your own class, that implements That ought to give you, what you need? Something like <?php
class Provider implements \PHPMailer\PHPMailer\OAuthTokenProvider {
private string $username;
private string $oauth;
public function __construct($username, $oauth) {
$this->username = $username;
$this->oauth = $oauth;
}
public function getOauth64() {
return base64_encode(
'user=' .
$this->username .
"\001auth=Bearer " .
$this->oauth .
"\001\001");
}
} And then use that in your mailer <?php
$provider = new Provider('username', 'token');
$mailer = new PHPMailer();
...
$mailer->setOAuth($provider);
$mailer->send(); |
Hi there, is there already a way to authenticate using xoauth2 authentication without the need to get a token?
I already have the token and to get PHPMailer to use it I had to:
set the AuthType parameter to XOAUTH2;
$mail->oauth = $oauthToken;
modify the SMTP.php implementation (line 598) like this:
// $oauth = $OAuth->getOauth64();
modify the PHPMailer.php implementation making the
$oauth
variable (line 365) publicpublic $oauth;
set the now available oauth parameter, like this
$mail->oauth = $oauthToken;
This way I was able to authenticate to the MS server and send an email.
Maybe there's already another way to do it but I didn't find it.
The text was updated successfully, but these errors were encountered: