我在忘记密码电子邮件发送时遇到错误错误= javax.mail.AuthenticationFailedException 这是我的代码 如何解决这个问题
protected void sendMail(String email,String activationLink,String msg){
java.util.Properties properties = new java.util.Properties();
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
javax.mail.Session mailSession = javax.mail.Session.getInstance(properties);
try {
MimeMessage message = new MimeMessage(mailSession);
message.setContent("<h1>Below is your "+msg+" Code</h1>"
+ "<a href='"+activationLink+"'> Click here to "+msg+" your account </a> "
+ ""
+ "","text/html" );
message.setSubject(msg);
InternetAddress sender = new InternetAddress("email", "password");
InternetAddress receiver = new InternetAddress(email);
message.setFrom(sender);
message.setRecipient(Message.RecipientType.TO, receiver);
message.saveChanges();
javax.mail.Transport transport = mailSession.getTransport("smtp");
transport.connect("smtp.gmail.com", 587, "myemailaddress", "password");
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (Exception e) {
System.out.println("err = " + e);
}
}
答案 0 :(得分:1)
您确定在此处具有正确的参数值:
transport.connect("smtp.gmail.com", 587, "myemailaddress", "password");
此外,as of this,动态IP地址的端口不同,请先阅读此介绍。