配置邮箱授权码。QQ配置授权码的链接:https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
授权码是邮箱推出的,用于登录第三方客户端的专用密码。Java使用邮箱发送邮件的时候要进行身份验证。用户名是邮箱账号,密码是授权码。
如:
final Session sendMailSession = Session.getDefaultInstance(prop, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("邮箱账号","授权码"); } });