版权声明:独学而无友,则孤陋寡闻。q群582951247 https://blog.csdn.net/mp624183768/article/details/85059153
因为项目需要,所以拿了之前发布的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;
}
}