title: Can't connect to Gmail SMTP secured with 2FA
body: <p>For some reason, I cannot send an email from my application using Google SMTP protocol. I receive a message that looks like that:</p>
  
  <pre><code>1. Unhandled javax.mail.AuthenticationFailedException
     534-5.7.14
     &lt;https://accounts.google.com/signin/continue?sarp=1&amp;scc=1&amp;plt=AKgnsbt0
     534-5.7.14
     joZVenRyJq1oMRdChfymgOOgcAmikBwqT-_rFkNsHtvsquevNauUwW34Ksg5n8kXxPTALF
     534-5.7.14
     SYbdpH4O4GEE2TXaQmHScXAY15r_00D-lmyVzoJs54ba6RrOYb-yVcFNpsZbxxonQckTgd
     534-5.7.14
     dxdnp69p7t3_xj5523el2LWvh_HPE2lKTgOr8yLkeXjrFKYhvJT1jRhb5-Sy3Rs3G7OjuS
     534-5.7.14 GdcriEyrrStn9Re4Vq7U46c5f8SwM&gt; Please log in via your
     web browser and 534-5.7.14 then try again.  534-5.7.14 Learn more
     at 534 5.7.14 https://support.google.com/mail/answer/78754
     c12-v6sm1390727lji.59 - gsmtp
  </code></pre>
  
  <p>Some facts:</p>
  
  <ul>
  <li>The web interface (gmail.com) works fine;</li>
  <li>I've got 2FA enabled;</li>
  <li>I use a new application password;</li>
  <li>IMAP is enabled in gmail settings, I checked it;</li>
  <li>Another account with 2FA and application password works fine in my app.</li>
  <li>Both accounts are in different Google custom domains. May it affect them somehow?</li>
  </ul>
  
  <p>Code (I use Clojure):</p>
  
  <pre><code>(def cred {:host "imap.gmail.com" 
             :user "user@my_domain.net" 
             :pass "application_password" 
             :ssl true})
  (send-message cred {:from "test@test.com" 
                      :to "bar@test.me" 
                      :subject "hello" 
                      :body "test"})
  </code></pre>
  
  <p>UPD: I also tried to follow the link from the response. It prompts me for 2FA and then redirects me to my account settings. Sending an email still doesn't work.</p>