At attempt to stitch Google's OAuth into the SMTP module. I've forked SMTP's 8.x-1.x and added in required code to make Google OAuth work.

8.x-1.x

Setup with Google OAuth is quite tricky. You can find instructions on the setup page at /admin/config/system/smtp_oauth_setup . This page not only walks through the Google Developer Console setup, but is required to pass the ClientID and Client Secret and retrieve the Refresh Token from Google.

The Google setup is quite finicky, so if you find you can't get a Refresh Token from the server, it might be easier to start over and set up again (at least delete and create a new Client ID). Once a Refresh token is generated, it won't be regenerated by the server. Resetting the Client Secret and keeping the ClientID will not work.

There may issues with gmail accounts that aren't part of GSuite (Though it's possible it might be sufficient to simply tell Google you want to bypass the security.

It should be possible to extend this with Microsoft and Yahoo OAuth, but that won't work with the code in this module.

This module is HIGHLY EXPERIMENTAL. This implementation is likely not the best way to solve this problem. I make no claims that this module is functional, and can't commit to supporting it. Do NOT use it on production sites, at least until others have had the chance to test it. My intention here is not to replace or fork SMTP, rather to create code that might be used by other projects (Ideally SMTP itself). If someone wants to steal the code or take over this fork project, I'm more than happy to share or hand it off.

Note that this module has composer requirements:

"league/oauth2-google": "^3.0",
"phpmailer/phpmailer": "^6.1"

You can add these by adding this module in your site's composer.json file:

"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "path",
"url": "web/modules/custom/smtp_oauth"
}
],
"require": {
"drupal/smtp_oauth": "dev-8.x-1.x"
},

8.x-2.x

This branch is based on
https://github.com/PHPMailer/PHPMailer/wiki/Gmail-XOAUTH2-Using-Google-…

It depends on
1) Google Api Client for authentication
2) Google Api PHP Client Library

The configuration is simple
1) After installing the module (assuming composer also installs google api client and the library, else you need to install them manually), goto /admin/config/system/smtp_oauth
2) Enter the Client ID and Client Secret from google console and save, this will create the required google api client account and show a message "You need to authenticate with google Authenticate Now"
3) Click Authenticate Now and it will open new tab where you can authenticate with your account.
4) After sucessfull authentication refresh the configuration page and it should show "Google account is authenticated, ready to send".

Note that this module has composer requirements:


"drupal/google_api_client": "^3.0",
"phpmailer/phpmailer": "^6.1"

You can add these by adding this module in your site's composer.json file:

"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "path",
"url": "web/modules/custom/smtp_oauth"
}
],
"require": {
"drupal/smtp_oauth": "dev-8.x-2.x"
},

It might be possible to backport this to Drupal 7, but it's going to be difficult.

For anyone who wants to work on this, see the following links for reference:

https://www.drupal.org/project/smtp/issues/3102055#comment-13460837

https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2

https://github.com/PHPMailer/PHPMailer/blob/master/get_oauth_token.php

https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail_xoaut…

Short name
3114402
Supporting organizations