java发送邮箱认证错误553 authentication is required
因为项目需要,所以拿了之前发布的java邮箱demo来修改,地址如下
http://blog.csdn.net/sun2015_07_24/article/details/50467133,
但是用的时候突然报这个错误
他说我的邮箱没有认证,我很奇怪,以前用的时候不出这错误的。现在却出现的。可能是邮箱服务器那边升级还是怎么了吧。。
那么我们解决这个错误的方法这么做。
错误说要我们认证。那我们就认证一下吧。代码如下
代码总的意思就是校验一下邮箱的用户名和密码是否正确
props.put("mail.smtp.auth", "true");
Authentication authentication = new Authentication(userName, userPwd);
Session session = Session.getDefaultInstance(props,authentication);
class Authentication extends Authenticator{
String username=null;
String password=null;
public Authentication(){
}
public Authentication(String username, String password) {
this.username = username;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication(){
PasswordAuthentication pa = new PasswordAuthentication(username, password);
return pa;
}
}
加入这些代码后执行。成功发送邮件
本文来自Herry小屋,作者:孙振光,转载请注明原文链接:https://www.cnblogs.com/sunzhenguang/p/15058954.html