0
这里我试图使用IMAP(gmail API)登录Gmail,但是当传递用户名&密码,然后即时获取Invocation TargetException。 这里是我的代码使用IMAP登录到Gmail的java.lang.reflect.InvocationTargetException
`Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "<username>@gmail.com", "<password>");
//Here im getting exception and below is the log
Exception in thread "main" javax.mail.AuthenticationFailedException: [ALERT] Please log in via your web browser: https://support.google.com/mail/accounts/answer/78754 (Failure)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:474)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
}
请帮助我如何解决this.Thank你。
请包括完整的堆栈跟踪。 – Max
@Max,即时得到以下异常:异常在线程“主要” javax.mail.AuthenticationFailedException:[ALERT]请通过网络浏览器登录:https://support.google.com/mail/accounts/answer/78754(失败) \t在com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:474) \t在javax.mail.Service.connect(Service.java:275) \t在javax.mail.Service.connect (Service.java:156) – khanam
您是否在您的Gmail帐户中启用了“安全性较低的应用程序”?你正在用gmail绊倒安全陷阱。有时候解决这个问题的唯一方法就是使用OAUTH2。 – Max