java发送邮箱认证错误553 authentication is required

来源:互联网 发布:龙傲天下战骑进阶数据 编辑:程序博客网 时间:2024/05/29 04:38

因为项目需要,所以拿了之前发布的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;      }      }

加入这些代码后执行。成功发送邮件
这里写图片描述

0 0
原创粉丝点击