在使用Javamail发邮件创建会话的时候,一般这么写
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, passwd);
}
此时会出现 javax.mail.AuthenticationFailedException,(ps:使用新浪邮箱就不会报错) 将username改成邮箱即可,不要使用用户名
Session session = Session.getInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username@xxx.com, passwd);
}