如何解决javax.mail.AuthenticationFailedException问题?

如何解决javax.mail.AuthenticationFailedException问题?,第1张

如何解决javax.mail.AuthenticationFailedException问题?

您需要实施一个自定义

Authenticator

import javax.mail.Authenticator;import javax.mail.PasswordAuthentication;class GMailAuthenticator extends Authenticator {     String user;     String pw;     public GMailAuthenticator (String username, String password)     {        super();        this.user = username;        this.pw = password;     }    public PasswordAuthentication getPasswordAuthentication()    {       return new PasswordAuthentication(user, pw);    }}

现在在

Session

Session session = Session.getInstance(props, new GMailAuthenticator(username, password));

另请查看JavaMail常见问题解答



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5488058.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存