发生javax.mail.AuthenticationFailedException并返回null

时间:2017-11-26 13:56:00

标签: android gmail javamail

我只是将邮件类引用到this

返回null时发生

javax.mail.AuthenticationFailedException

  

11-26 22:51:25.053 19008-20169 / com.example.android.mailGenerater E / AndroidRuntime:FATAL EXCEPTION:Thread-7                                                                                过程:com.example.android.mailGenerater,PID:19008                                                                                javax.mail.AuthenticationFailedException                                                                                    在javax.mail.Service.connect(Service.java:319)                                                                                    在javax.mail.Service.connect(Service.java:169)                                                                                    在javax.mail.Service.connect(Service.java:118)                                                                                    在javax.mail.Transport.send0(Transport.java:188)                                                                                    在javax.mail.Transport.send(Transport.java:118)                                                                                    在com.example.android.mailGenerater.SendGmailManager(SendGmailManager.kt:145)                                                                                    在com.example.android.mailGenerater.MyActivity $ onCreate $ 1 $ 1.run(MyActivity.kt:60)

我用exception代码

 catch (e: AuthenticationFailedException) {
        Log.d(TAG, "auth failed : ${e.localizedMessage}") // print : "auth failed : null"
        e.printStackTrace() // not working.

它没有显示任何内容。

该异常返回null,因此打印堆栈跟踪无效。

我想知道 当AuthenticationFailedException出现时为null

1 个答案:

答案 0 :(得分:0)

抱歉

这个问题依赖于我所有的错误。

我错过了javax.mail.Authenticator

的子课程中的贝娄代码
protected PasswordAuthentication getPasswordAuthentication() {   
    return new PasswordAuthentication(user, password);   
} 

如果没有Null occurred

,我认为override method : getPasswordAuthentication()

当我添加覆盖方法时,它的效果非常好。