title: Gmail smtp xoauth2 via laminas(zend)mail
body: <p>I have a small problem with gmail authentication, trying to connect via the token received by OAuth2.</p>
  
  <p>I put my code below.</p>
  
  <pre><code>try {
          $xOAuthRequest = base64_encode('user=' . $account-&gt;getSmtpServer()-&gt;getLogin() . "\1auth=Bearer " . $account-&gt;getOAuthToken()-&gt;getToken() . "\1\1");
          $transport = new TransportSmtp();
  
          $options = new SmtpOptions([
              'host' =&gt; 'smtp.gmail.com',
              //'port' =&gt; 587,
              'connection_class' =&gt; 'smtp',
              'connection_config' =&gt; [
                  'username' =&gt; $account-&gt;getSmtpServer()-&gt;getLogin(),
                  //'password' =&gt; $account-&gt;getSmtpServer()-&gt;getPassword(),
                  'ssl' =&gt; 'tls',
                  'port' =&gt; 587,
                  'auth' =&gt; 'xoauth',
                  'xoauth_request' =&gt; $xOAuthRequest
              ]
          ]);
  
          $transport-&gt;setOptions($options);
          $this-&gt;setTransport($transport);
  
      } catch (Exception $exception){
          dump($exception);
      }
  </code></pre>
  
  <p>Code return:</p>
  
  <pre><code>5.7.0 Authentication Required. Learn more at 5.7.0 https://support.google.com/mail/?p=WantAuthError v23sm426024ljg.122 - gsmtp
  </code></pre>
  
  <p>I also tried with SSL and port 465 and with the password uncommented.</p>
  
  <p>What am I doing wrong?</p>