title: GMail Username and Password not accepted error when sending email with SwiftMailer
body: <p>I get the following error when trying to use my GMail account to send an email from my <a href="http://www.crmpicco.co.uk/" rel="nofollow">PHP application</a> with SwiftMailer. </p>
  
  <pre><code>535-5.7.8 Username and Password not accepted
  </code></pre>
  
  <p>This is my SwiftMailer code:</p>
  
  <pre><code>$transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
      -&gt;setUsername('ayrshireminiscontact@gmail.com')
      -&gt;setPassword('~password-in-here~');
  
  $mailer  = Swift_Mailer::newInstance($transporter);
  $message = Swift_Message::newInstance('Portfolio Enquiry')
      -&gt;setFrom(array('ayrshireminiscontact@gmail.com' =&gt; 'CRMPicco Portfolio Enquiry'))
      -&gt;setTo(array('picco@crmpicco.co.uk' =&gt; 'A name'))
      -&gt;setBody($email_body);
  
  $result = $mailer-&gt;send($message);
  </code></pre>
  
  <p>This is the entry in my Apache error log and the stack trace.</p>
  
  <blockquote>
    <p>[Wed Aug 18 22:06:10.284728 2015] [:error] [pid 9298] [client
    10.0.0.1:64806] PHP Fatal error:  Uncaught exception 'Swift_TransportException' with message 'Expected response code 250
    but got code "535", with message "535-5.7.8 Username and Password not
    accepted. Learn more at\r\n535 5.7.8 
    <a href="https://support.google.com/mail/answer/14257" rel="nofollow">https://support.google.com/mail/answer/14257</a> gj13sm2191931wic.22 -
    gsmtp\r\n"' in
    /var/www/portfolio/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383\nStack
    trace:\n#0
    /var/www/portfolio/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(281):
    Swift_Transport_AbstractSmtpTransport->_assertResponseCode('535-5.7.8
    Usern...', Array)\n#1
    /var/www/portfolio/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(243):
    Swift_Transport_AbstractSmtpTransport->executeCommand('RSET\r\n',
    Array, Array)\n#2
    /var/www/portfolio/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php(54):
    Swift_Transport_EsmtpTransport->executeCommand('RSET\r\n',
    Array)\n#3
    /var/www/portfolio/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php(176):
    Swift_Transport_Esmtp_Auth_XOAuth2Authent in
    /var/www/portfolio/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php
    on line 383, referer: <a href="https://crmpicco.dev/" rel="nofollow">https://crmpicco.dev/</a></p>
  </blockquote>
  
  <p>I have tried <a href="http://www.google.com/accounts/DisplayUnlockCaptcha" rel="nofollow">http://www.google.com/accounts/DisplayUnlockCaptcha</a> and I can log in to the account through a web browser without any problems.</p>
  
  <p>This happens on my local development machine and the publically-accesible site. Is this an issue with my GMail account or my implementation?</p>