title: Gmail SMTP, CLIENT -> SERVER: AUTH XOAUTH2, SMTP ERROR: AUTH command failed: 334
body: <p>I am trying to hook in <a href="https://wordpress.org/plugins/gmail-smtp/" rel="nofollow noreferrer">Gmail SMTP v1.1.7 plugin</a>.</p>
  
  <p>I have already successfully activated it by going to google developer console, getting OAuth key </p>
  
  <p><a href="https://i.stack.imgur.com/ndpuc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ndpuc.png" alt="enter image description here"></a></p>
  
  <p>then connecting the plugin with Gmail</p>
  
  <p><a href="https://i.stack.imgur.com/4fVJ3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4fVJ3.png" alt="enter image description here"></a></p>
  
  <p>However when I try to send test email I get Authentication error</p>
  
  <blockquote>
    <p>Server Info
    2018-04-15 00:46:32 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)<br>
    2018-04-15 00:46:33 Connection: opened<br>
    2018-04-15 00:46:33 SMTP -> get_lines(): $data is ""<br>
    2018-04-15 00:46:33 SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP e77sm21399032pfk.147 - gsmtp"<br>
    2018-04-15 00:46:33 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP e77sm21399032pfk.147 - gsmtp<br>
    2018-04-15 00:46:33 CLIENT -> SERVER: EHLO localhost<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $data is ""<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [113.166.92.87]"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $str is "250-SIZE 35882577"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $str is "250-8BITMIME"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $str is "250-STARTTLS"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-STARTTLS"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $str is "250-PIPELINING"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $str is "250-CHUNKING"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING"<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $str is "250 SMTPUTF8"<br>
    2018-04-15 00:46:34 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>
    2018-04-15 00:46:34 CLIENT -> SERVER: STARTTLS<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $data is ""<br>
    2018-04-15 00:46:34 SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS"<br>
    2018-04-15 00:46:34 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS<br>
    2018-04-15 00:46:34 CLIENT -> SERVER: EHLO localhost<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $data is ""<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [113.166.92.87]"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $str is "250-SIZE 35882577"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $str is "250-8BITMIME"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $str is "250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $str is "250-PIPELINING"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $str is "250-CHUNKING"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING"<br>
    2018-04-15 00:46:35 SMTP -> get_lines(): $str is "250 SMTPUTF8"<br>
    2018-04-15 00:46:35 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [113.166.92.87]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8<br>
    2018-04-15 00:46:35 Auth method requested: XOAUTH2<br>
    2018-04-15 00:46:35 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH<br>
    2018-04-15 00:46:36 CLIENT -> SERVER: AUTH XOAUTH2 [somethingEncriptedHere]=<br>
    2018-04-15 00:46:36 SMTP -> get_lines(): $data is ""<br>
    2018-04-15 00:46:36 SMTP -> get_lines(): $str is "334 [somethingShorteEncriptedHere]=="<br>
    2018-04-15 00:46:36 SERVER -> CLIENT: 334 [somethingShorteEncriptedHere]==<br>
    2018-04-15 00:46:36 SMTP ERROR: AUTH command failed: 334 [somethingShorterEncriptedHere]==<br>
    SMTP Error: Could not authenticate.<br>
    2018-04-15 00:46:36 CLIENT -> SERVER: QUIT    </p>
  </blockquote>
  
  <p>It then tries to use Username and password but fails too.</p>
  
  <p>Relevant part of the log is </p>
  
  <blockquote>
    <p>2018-04-15 00:46:35 Auth method requested: XOAUTH2    //negotiates the method of authentication<br>
    2018-04-15 00:46:35 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH    //negotiates the method of authentication<br>
    2018-04-15 00:46:36 CLIENT -> SERVER: AUTH XOAUTH2 [somethingEncriptedHere]=    //sends encrypted client secret(my guess)<br>
    2018-04-15 00:46:36 SMTP -> get_lines(): $data is ""<br>
    2018-04-15 00:46:36 SMTP -> get_lines(): $str is "334 [somethingShorterEncriptedHere]=="<br>
    2018-04-15 00:46:36 SERVER -> CLIENT: 334 [somethingShorterEncriptedHere]==<br>
    2018-04-15 00:46:36 SMTP ERROR: AUTH command failed: 334 [somethingShorterEncriptedHere]==    //fails
    SMTP Error: Could not authenticate.<br>
    2018-04-15 00:46:36 CLIENT -> SERVER: QUIT    </p>
  </blockquote>
  
  <p>I am not sure why does it fail on authentication if it already has successfully connected/registered the Gmail plugin with gmail?</p>