Can't connect to Gmail SMTP secured with 2FA

烂漫一生 提交于 2020-01-06 07:15:11

问题


For some reason, I cannot send an email from my application using Google SMTP protocol. I receive a message that looks like that:

1. Unhandled javax.mail.AuthenticationFailedException
   534-5.7.14
   <https://accounts.google.com/signin/continue?sarp=1&scc=1&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> 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

Some facts:

  • The web interface (gmail.com) works fine;
  • I've got 2FA enabled;
  • I use a new application password;
  • IMAP is enabled in gmail settings, I checked it;
  • Another account with 2FA and application password works fine in my app.
  • Both accounts are in different Google custom domains. May it affect them somehow?

Code (I use Clojure):

(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"})

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.


回答1:


After 8 hours of trying this and that I found an option in Google Apps. Go to Security -> Advanced -> Check "Allow users to manage their security settings" (it was disabled). Now it works, oh gosh.




回答2:


Not exactly sure which options the answer Ivan provided is referring to. They don't appear in my non-gapps account perhaps due to a UI update.

I had a similar problem with a nas cage configured to use a Gmail SMTP to send alert emails. Once I enabled 2FA on the Gmail account the emails would fail.

The solution was to create an 'App Password' under the google account security tab. Essentially these are passwords created on a per-app basis for programs/devices that do not support 2FA. Once you create the password, you use it in place of the original Gmail password for that specific app only. Here's a direct link to the Google Security App Password Page



来源:https://stackoverflow.com/questions/50419239/cant-connect-to-gmail-smtp-secured-with-2fa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!