忘记密码的电子邮件发送err = 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);
}
}
最佳答案
您确定此处的参数值正确吗:
transport.connect("smtp.gmail.com", 587, "myemailaddress", "password");
此外,as of this,动态IP地址的端口是不同的,请先阅读此介绍。