我正在尝试使用Oauth2 for Gmail连接SMTP,但遇到以下问题。
Oauth令牌和电子邮件名称是正确的,可用于连接IMAP。
我正在关注example of google。
DEBUG SMTP: Authenticate with SASL
DEBUG SMTP: SASL mechanisms allowed: XOAUTH2
DEBUG SMTP: SASL AUTH command trace suppressed
DEBUG SMTP SASL: Mechanisms: XOAUTH2
DEBUG SMTP SASL: No SASL support
DEBUG SMTP: SASL authentication failed
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
javax.mail.AuthenticationFailedException: 535-5.7.1 Username and Password not accepted. Learn more at
535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 ol4sm17455809pbb.58
答案 0 :(得分:1)
我忘了调用OAuth2Authenticator类的initialize()方法。
public static void initialize() {
Security.addProvider(new OAuth2Provider());
}