问题
I am unable to authenticate IMAP with Yahoo and cannot pinpoint the cause. Can anyone help me to get more information other than the exception below?
"javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Invalid credentials (Failure)"
Yahoo seems to have had many revisions to authentication over the years so that is why I put the current year in the title. Here is my setup:
On Yahoo: I have enabled less secure apps; I have checked and recheck credentials.
On my linux box: I have proven that IMAP works by using Thunderbird to connect and browse mail.
Here is the code:
1 private static final String email_id = "xxxxxxxx@yahoo.com";
2 private static final String password = {"xxxxxxxx"};
3
4 public static void main(String[] args) {
5
6 Properties properties = new Properties();
7 //yahoo
8 properties.put("mail.store.protocol", "imap");
9 properties.put("mail.imaps.host","imap.mail.yahoo.com");
10 properties.put("mail.imaps.port", "993");
11 properties.put("mail.imap.ssl.enable", "true");
12 properties.put("mail.imap.mail.auth", "true");
13
14 try {
15 Session session = Session.getDefaultInstance(properties, null);
16 Store store = session.getStore("imaps");
17
18 store.connect(email_id, password);
19
20 ...
21
22 store.close();
23 } catch (Exception e) {
24 e.printStackTrace();
25 }
26 } // end of main
27 }
回答1:
Found the debugging answer. Included debugging on the Session object.
session.setDebug(true);
来源:https://stackoverflow.com/questions/49631965/debugging-imap-access-of-yahoo-in-2018