1、发送邮件时验证失败
a)查看用户名密码是否正确
b)查看是否开启邮箱授权码,若开启邮箱授权码,则密码为授权码
to_mail_address = mails[i];
Authenticator auth = new PopupAuthenticator(username, password);
Properties mailProps = new Properties();
mailProps.put("mail.smtp.auth", "true");
mailProps.put("username", username);
mailProps.put("password", password);
mailProps.put("mail.smtp.host", smtp_server);
//Session mailSession = Session.getDefaultInstance(mailProps,auth);
Session mailSession = Session.getInstance(mailProps, auth);
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from_mail_address));
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(to_mail_address));
message.setSubject(domainname+" to "+to_mail_address);
MimeMultipart multi = new MimeMultipart();
BodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setText(msg+" send to "+to_mail_address);
multi.addBodyPart(textBodyPart);
message.setContent(multi);
message.saveChanges();
Transport.send(message);
2、发送邮件时被发件服务器当垃圾邮件退回,或被收件服务器当垃圾邮件退回
在白名单添加相应地址