is_php_compatible() ) { return; } } /** * Re-use the MailCatcher class methods and properties. * * @since 1.2.0 * * @param \WPMailSMTP\MailCatcher $phpmailer */ public function process_phpmailer( $phpmailer ) { // Make sure that we have access to MailCatcher class methods. if ( ! $phpmailer instanceof MailCatcher && ! $phpmailer instanceof \PHPMailer ) { return; } $this->phpmailer = $phpmailer; } /** * Use Google API Services to send emails. * * @since 1.0.0 */ public function send() { // Include the Google library. require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php'; $auth = new Auth(); $message = new \Google_Service_Gmail_Message(); // Get the raw MIME email using \MailCatcher data. $base64 = str_replace( array( '+', '/', '=' ), array( '-', '_', '' ), base64_encode( $this->phpmailer->getSentMIMEMessage() ) ); // url safe. $message->setRaw( $base64 ); $service = new \Google_Service_Gmail( $auth->get_client() ); try { $response = $service->users_messages->send( 'me', $message ); $this->process_response( $response ); } catch ( \Exception $e ) { Debug::set( 'Mailer: Gmail' . "\r\n" . $e->getMessage() ); return; } } /** * Save response from the API to use it later. * * @since 1.0.0 * * @param \Google_Service_Gmail_Message $response */ protected function process_response( $response ) { $this->response = $response; } /** * Check whether the email was sent. * * @since 1.0.0 * * @return bool */ public function is_email_sent() { $is_sent = false; if ( method_exists( $this->response, 'getId' ) ) { $message_id = $this->response->getId(); if ( ! empty( $message_id ) ) { $is_sent = true; } } // Clear debug messages if email is successfully sent. if ( $is_sent ) { Debug::clear(); } return $is_sent; } /** * @inheritdoc */ public function get_debug_info() { $gmail_text = array(); $options = new \WPMailSMTP\Options(); $gmail = $options->get_group( 'gmail' ); $gmail_text[] = 'Client ID/Secret: ' . ( ! empty( $gmail['client_id'] ) && ! empty( $gmail['client_secret'] ) ? 'Yes' : 'No' ); $gmail_text[] = 'Auth Code: ' . ( ! empty( $gmail['auth_code'] ) ? 'Yes' : 'No' ); $gmail_text[] = 'Access Token: ' . ( ! empty( $gmail['access_token'] ) ? 'Yes' : 'No' ); $gmail_text[] = '
Server:'; $gmail_text[] = 'OpenSSL: ' . ( extension_loaded( 'openssl' ) ? 'Yes' : 'No' ); $gmail_text[] = 'PHP.allow_url_fopen: ' . ( ini_get( 'allow_url_fopen' ) ? 'Yes' : 'No' ); $gmail_text[] = 'PHP.stream_socket_client(): ' . ( function_exists( 'stream_socket_client' ) ? 'Yes' : 'No' ); $gmail_text[] = 'PHP.fsockopen(): ' . ( function_exists( 'fsockopen' ) ? 'Yes' : 'No' ); $gmail_text[] = 'PHP.curl_version(): ' . ( function_exists( 'curl_version' ) ? 'Yes' : 'No' ); if ( function_exists( 'apache_get_modules' ) ) { $modules = apache_get_modules(); $gmail_text[] = 'Apache.mod_security: ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' ); } if ( function_exists( 'selinux_is_enabled' ) ) { $gmail_text[] = 'OS.SELinux: ' . ( selinux_is_enabled() ? 'Yes' : 'No' ); } if ( function_exists( 'grsecurity_is_enabled' ) ) { $gmail_text[] = 'OS.grsecurity: ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' ); } return implode( '
', $gmail_text ); } }