Skip to content
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

Create sendoauth2.phps #2985

Merged
merged 2 commits into from
Nov 25, 2023
Merged

Create sendoauth2.phps #2985

merged 2 commits into from
Nov 25, 2023

Conversation

decomplexity
Copy link
Contributor

OAuth2 authentication for both Microsoft 365 Exchange email and Google Gmail. Client secrets and X.509 certificates are supported for Exchange. Client secrets are supported for Gmail. Authorization_code grant flow and client_credentials grant flow for SMTP are supported for Exchange. Authorization_code grant flow is supported for Gmail.

OAuth2 authentication for both Microsoft 365 Exchange email and Google Gmail. Client secrets and X.509 certificates are supported for Exchange. Client secrets are supported for Gmail. Authorization_code grant flow and client_credentials grant flow for SMTP are supported for Exchange. Authorization_code grant flow is supported for Gmail.
Copy link
Member

@Synchro Synchro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this - I know you've been very helpful in decrypting the intricacies of inconsistent OAuth implementations!

*/

//Set the wrapper namespace
namespace decomplexity\SendOauth2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the right way to work with external libraries. The namespace should be up to the developer, and if they want to use your class, they should import it using:

use decomplexity\SendOauth2\SendOauth2B;

Just as they do for PHPMailer.

//Sender and recipients
$mail->setFrom('from@example.com', 'Mailer'); // 'Header' From address with optional sender name
$mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient
$mail->addAddress('ellen@example.com'); //Name is optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the purpose of this example is purely to demonstrate how to use your auth wrapper, I suggest removing anything that is covered in other examples, such as extra recipients, attachments, etc.

$mail->Host = 'smtp.office365.com'; //Set the SMTP server (smtp.gmail.com for Gmail)
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = 'user@example.com'; //SMTP username
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable implicit TLS encryption
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These days we should be recommending SMTPS on port 465, as per RFC8314:

$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;


$mail->setOAuth($oauthTokenProvider); //Pass OAuthTokenProvider to PHPMailer

//Attachments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, I suggest removing these attachment lines.

Updated from @Synchro's comments
@Synchro Synchro merged commit d327514 into PHPMailer:master Nov 25, 2023
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants