天天看點

Java發送郵件報錯【javax.mail.AuthenticationFailedException: failed to connect, no password specified?】

弄了個發送郵件的小功能,結果報錯 javax.mail.AuthenticationFailedException: failed to connect, no password specified?

查了下才知道

從網上又搜了下,最終在 https://blog.csdn.net/a1124544556/article/details/80571266 位址中找到了答案。

讓一個方法繼承Authenticator,并重寫protected PasswordAuthentication getPasswordAuthentication() {}方法。

建立Session時,Session.getInstance(properties, Authenticator);

即可。