updated plugin WP Mail SMTP
version 2.1.1
This commit is contained in:
@ -92,26 +92,28 @@ class Mailer extends MailerAbstract {
|
||||
$this->phpmailer->Sender = $gmail_creds['email'];
|
||||
}
|
||||
|
||||
// Get the raw MIME email using MailCatcher data.
|
||||
// We need here to make base64URL-safe string.
|
||||
$base64 = str_replace(
|
||||
array( '+', '/', '=' ),
|
||||
array( '-', '_', '' ),
|
||||
base64_encode( $this->phpmailer->getSentMIMEMessage() )
|
||||
);
|
||||
|
||||
$message->setRaw( $base64 );
|
||||
|
||||
$service = new \Google_Service_Gmail( $auth->get_client() );
|
||||
|
||||
try {
|
||||
// Prepare a message for sending.
|
||||
$this->phpmailer->preSend();
|
||||
|
||||
// Get the raw MIME email using MailCatcher data.
|
||||
// We need here to make base64URL-safe string.
|
||||
$base64 = str_replace(
|
||||
[ '+', '/', '=' ],
|
||||
[ '-', '_', '' ],
|
||||
base64_encode( $this->phpmailer->getSentMIMEMessage() ) //phpcs:ignore
|
||||
);
|
||||
|
||||
$message->setRaw( $base64 );
|
||||
|
||||
$service = new \Google_Service_Gmail( $auth->get_client() );
|
||||
$response = $service->users_messages->send( 'me', $message );
|
||||
|
||||
$this->process_response( $response );
|
||||
} catch ( \Exception $e ) {
|
||||
Debug::set(
|
||||
'Mailer: Gmail' . "\r\n" .
|
||||
$e->getMessage()
|
||||
$this->process_exception_message( $e->getMessage() )
|
||||
);
|
||||
|
||||
return;
|
||||
@ -124,7 +126,7 @@ class Mailer extends MailerAbstract {
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Added action "wp_mail_smtp_providers_gmail_mailer_process_response" with $response.
|
||||
*
|
||||
* @param \Google_Service_Gmail_Message $response
|
||||
* @param \Google_Service_Gmail_Message $response Instance of Gmail response.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
@ -160,7 +162,12 @@ class Mailer extends MailerAbstract {
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* This method is relevant to SMTP and Pepipost.
|
||||
* All other custom mailers should override it with own information.
|
||||
*
|
||||
* @since 1.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
@ -200,7 +207,11 @@ class Mailer extends MailerAbstract {
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* @since 1.4.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
@ -219,4 +230,75 @@ class Mailer extends MailerAbstract {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the exception message and append additional explanation to it.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param mixed $message A string or an object with strings.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function process_exception_message( $message ) {
|
||||
|
||||
// Transform the passed message to a string.
|
||||
if ( ! is_string( $message ) ) {
|
||||
$message = wp_json_encode( $message );
|
||||
} else {
|
||||
$message = wp_strip_all_tags( $message, false );
|
||||
}
|
||||
|
||||
// Define known errors, that we will scan the message with.
|
||||
$known_errors = array(
|
||||
array(
|
||||
'errors' => array(
|
||||
'invalid_grant',
|
||||
),
|
||||
'explanation' => esc_html__( 'Please re-grant Google app permissions!', 'wp-mail-smtp' ) . ' ' . PHP_EOL .
|
||||
esc_html__( 'Go to WP Mail SMTP plugin settings page. Click the “Remove Connection” button.', 'wp-mail-smtp' ) . ' ' . PHP_EOL .
|
||||
esc_html__( 'Then click the “Allow plugin to send emails using your Google account” button and re-enable access.', 'wp-mail-smtp' ),
|
||||
),
|
||||
);
|
||||
|
||||
// Check if we get a match and append the explanation to the original message.
|
||||
foreach ( $known_errors as $error ) {
|
||||
foreach ( $error['errors'] as $error_fragment ) {
|
||||
if ( false !== strpos( $message, $error_fragment ) ) {
|
||||
return $message . PHP_EOL . $error['explanation'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we get no match we return the original message (as a string).
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default email addresses for the reply to email parameter.
|
||||
*
|
||||
* @deprecated 2.1.1
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @since 2.1.1 Not used anymore.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function default_reply_to_addresses() {
|
||||
|
||||
_deprecated_function( __CLASS__ . '::' . __METHOD__, '2.1.1 of WP Mail SMTP plugin' );
|
||||
|
||||
$gmail_creds = ( new Auth() )->get_user_info();
|
||||
|
||||
if ( empty( $gmail_creds['email'] ) ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
$gmail_creds['email'] => [
|
||||
$gmail_creds['email'],
|
||||
'',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user