-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RELEASE 1.5.0. Requires PHP >= 7.3.0. XOAUTH2 authentication has been…
… added.
- Loading branch information
1 parent
641b36a
commit 83b3869
Showing
6 changed files
with
210 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,13 @@ | |
A CodeIgniter compatible email-library powered by PHPMailer | ||
=========================================================== | ||
|
||
Version: 1.4.7 | ||
Author: Ivan Tcholakov <[email protected]>, 2012-2021. | ||
Version: 1.5.0 | ||
Author: Ivan Tcholakov <[email protected]>, 2012-2022. | ||
License: The MIT License (MIT), http://opensource.org/licenses/MIT | ||
|
||
This library is compatible with CodeIgniter 3.1.x and PHP >= 5.5.0. | ||
This library is compatible with CodeIgniter 3.1.x and PHP >= 7.3.0. | ||
|
||
Tested on CodeIgniter 3.1.11 (September 19th, 2019) and PHPMailer Version 6.2.0 (November 25th, 2020). | ||
Tested on CodeIgniter 3.1.13 (March 3rd, 2022) and PHPMailer Version 6.6.4 (August 22nd, 2022). | ||
|
||
Links | ||
----- | ||
|
@@ -117,7 +117,7 @@ $config['mailpath'] = '/usr/sbin/sendmail'; | |
$config['smtp_host'] = 'smtp.gmail.com'; | ||
$config['smtp_auth'] = true; // Whether to use SMTP authentication, boolean TRUE/FALSE. If this option is omited or if it is NULL, then SMTP authentication is used when both $config['smtp_user'] and $config['smtp_pass'] are non-empty strings. | ||
$config['smtp_user'] = '[email protected]'; | ||
$config['smtp_pass'] = 'yourpassword'; | ||
$config['smtp_pass'] = ''; // Gmail disabled the so-called "Less Secured Applications", your Google password is not to be used directly, XOAUTH2 authentication will be used. | ||
$config['smtp_port'] = 587; | ||
$config['smtp_timeout'] = 30; // (in seconds) | ||
$config['smtp_crypto'] = 'tls'; // '' or 'tls' or 'ssl' | ||
|
@@ -137,6 +137,20 @@ $config['bcc_batch_mode'] = false; | |
$config['bcc_batch_size'] = 200; | ||
$config['encoding'] = '8bit'; // The body encoding. For CodeIgniter: '8bit' or '7bit'. For PHPMailer: '8bit', '7bit', 'binary', 'base64', or 'quoted-printable'. | ||
|
||
// XOAUTH2 mechanism for authentication. | ||
// See https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2 | ||
$config['oauth_type'] = 'xoauth2_google'; // XOAUTH2 authentication mechanism: | ||
// '' - disabled; | ||
// 'xoauth2' - custom implementation; | ||
// 'xoauth2_google' - Google provider; | ||
// 'xoauth2_yahoo' - Yahoo provider; | ||
// 'xoauth2_microsoft' - Microsoft provider. | ||
$config['oauth_instance'] = null; // Initialized instance of \PHPMailer\PHPMailer\OAuth (OAuthTokenProvider interface) that contains a custom token provider. Needed for 'xoauth2' custom implementation only. | ||
$config['oauth_user_email'] = ''; // If this option is an empty string or null, $config['smtp_user'] will be used. | ||
$config['oauth_client_id'] = '237644427849-g8d0pnkd1jh3idcjdbopvkse2hvj0tdp.apps.googleusercontent.com'; | ||
$config['oauth_client_secret'] = 'mklHhrns6eF-qjwuiLpSB4DL'; | ||
$config['oauth_refresh_token'] = '1/7Jt8_RHX86Pk09VTfQd4O_ZqKbmuV7HpMNz-rqJ4KdQMEudVrK5jSpoR30zcRFq6'; | ||
|
||
// DKIM Signing | ||
$config['dkim_domain'] = ''; // DKIM signing domain name, for exmple 'example.com'. | ||
$config['dkim_private'] = ''; // DKIM private key, set as a file path. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
|
||
/** | ||
* CodeIgniter compatible email-library powered by PHPMailer. | ||
* Version: 1.4.6 | ||
* @author Ivan Tcholakov <[email protected]>, 2012-2020. | ||
* Version: 1.5.0 | ||
* @author Ivan Tcholakov <[email protected]>, 2012-2022. | ||
* @license The MIT License (MIT), http://opensource.org/licenses/MIT | ||
* @link https://github.com/ivantcholakov/codeigniter-phpmailer | ||
* | ||
* Tested on CodeIgniter 3.1.11 (September 19th, 2019) and | ||
* PHPMailer Version 6.2.0 (November 25th, 2020). | ||
* Tested on CodeIgniter 3.1.13 (March 3rd, 2022) and | ||
* PHPMailer Version 6.6.4 (August 22nd, 2022). | ||
*/ | ||
|
||
class MY_Email extends CI_Email { | ||
|
@@ -46,6 +46,12 @@ class MY_Email extends CI_Email { | |
'encoding' => '8bit', | ||
'smtp_auto_tls' => true, | ||
'smtp_conn_options' => array(), | ||
'oauth_type' => '', | ||
'oauth_instance' => null, | ||
'oauth_user_email' => '', | ||
'oauth_client_id' => '', | ||
'oauth_client_secret' => '', | ||
'oauth_refresh_token' => '', | ||
'dkim_domain' => '', | ||
'dkim_private' => '', | ||
'dkim_private_string' => '', | ||
|
@@ -556,6 +562,100 @@ public function send($auto_clear = true) { | |
// | ||
} | ||
|
||
switch ($this->oauth_type) { | ||
|
||
case 'xoauth2': | ||
|
||
$this->phpmailer->AuthType = 'XOAUTH2'; | ||
|
||
$this->phpmailer->setOAuth($this->oauth_instance); | ||
|
||
break; | ||
|
||
case 'xoauth2_google': | ||
|
||
$this->phpmailer->AuthType = 'XOAUTH2'; | ||
|
||
$provider = new \League\OAuth2\Client\Provider\Google( | ||
array( | ||
'clientId' => $this->oauth_client_id, | ||
'clientSecret' => $this->oauth_client_secret, | ||
) | ||
); | ||
|
||
$this->phpmailer->setOAuth(new \PHPMailer\PHPMailer\OAuth( | ||
array( | ||
'provider' => $provider, | ||
'clientId' => $this->oauth_client_id, | ||
'clientSecret' => $this->oauth_client_secret, | ||
'refreshToken' => $this->oauth_refresh_token, | ||
'userName' => $this->oauth_user_email != '' ? $this->oauth_user_email : $this->smtp_user, | ||
) | ||
) | ||
); | ||
|
||
break; | ||
|
||
case 'xoauth2_yahoo': | ||
|
||
$this->phpmailer->AuthType = 'XOAUTH2'; | ||
|
||
$provider = new \Hayageek\OAuth2\Client\Provider\Yahoo( | ||
array( | ||
'clientId' => $this->oauth_client_id, | ||
'clientSecret' => $this->oauth_client_secret, | ||
) | ||
); | ||
|
||
$this->phpmailer->setOAuth(new \PHPMailer\PHPMailer\OAuth( | ||
array( | ||
'provider' => $provider, | ||
'clientId' => $this->oauth_client_id, | ||
'clientSecret' => $this->oauth_client_secret, | ||
'refreshToken' => $this->oauth_refresh_token, | ||
'userName' => $this->oauth_user_email != '' ? $this->oauth_user_email : $this->smtp_user, | ||
) | ||
) | ||
); | ||
|
||
break; | ||
|
||
case 'xoauth2_microsoft': | ||
|
||
$this->phpmailer->AuthType = 'XOAUTH2'; | ||
|
||
$provider = new \Stevenmaguire\OAuth2\Client\Provider\Microsoft( | ||
array( | ||
'clientId' => $this->oauth_client_id, | ||
'clientSecret' => $this->oauth_client_secret, | ||
) | ||
); | ||
|
||
$this->phpmailer->setOAuth(new \PHPMailer\PHPMailer\OAuth( | ||
array( | ||
'provider' => $provider, | ||
'clientId' => $this->oauth_client_id, | ||
'clientSecret' => $this->oauth_client_secret, | ||
'refreshToken' => $this->oauth_refresh_token, | ||
'userName' => $this->oauth_user_email != '' ? $this->oauth_user_email : $this->smtp_user, | ||
) | ||
) | ||
); | ||
|
||
break; | ||
|
||
default: | ||
|
||
$this->phpmailer->AuthType = ''; | ||
|
||
$reflection = new \ReflectionClass($this->phpmailer); | ||
$property = $reflection->getProperty('oauth'); | ||
$property->setAccessible(true); | ||
$property->setValue($this->phpmailer, null); | ||
|
||
break; | ||
} | ||
|
||
$result = (bool) $this->phpmailer->send(); | ||
|
||
if ($result) { | ||
|
@@ -640,6 +740,7 @@ public function set_mailpath($value) { | |
|
||
public function set_protocol($protocol = 'mail') { | ||
|
||
$protocol = (string) $protocol; | ||
$protocol = in_array($protocol, self::$protocols, TRUE) ? strtolower($protocol) : 'mail'; | ||
|
||
$this->properties['protocol'] = $protocol; | ||
|
@@ -1059,6 +1160,65 @@ public function set_smtp_conn_options($value) { | |
return $this; | ||
} | ||
|
||
// XOAUTH2 settings. | ||
|
||
public function set_oauth_type($value) { | ||
|
||
$value = strtolower(trim((string) $value)); | ||
|
||
if ($value != '' && strpos($value, 'xoauth2') === false) { | ||
$value = 'xoauth2'; | ||
} | ||
|
||
$this->properties['oauth_type'] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function set_oauth_instance($value) { | ||
|
||
// An object that implements PHPMailer OAuthTokenProvider interface or null is expected here. | ||
$this->properties['oauth_instance'] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function set_oauth_user_email($value) { | ||
|
||
$value = (string) $value; | ||
|
||
$this->properties['oauth_user_email'] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function set_oauth_client_id($value) { | ||
|
||
$value = (string) $value; | ||
|
||
$this->properties['oauth_client_id'] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function set_oauth_client_secret($value) { | ||
|
||
$value = (string) $value; | ||
|
||
$this->properties['oauth_client_secret'] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function set_oauth_refresh_token($value) { | ||
|
||
$value = (string) $value; | ||
|
||
$this->properties['oauth_refresh_token'] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
// DKIM signing, see https://github.com/ivantcholakov/codeigniter-phpmailer/issues/11 | ||
|
||
// PHPMailer: DKIM signing domain name, for exmple 'example.com'. | ||
|
83b3869
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please i need a mailer like this someone help