我在忘記密碼電子郵件發送時收到以下錯誤err = javax.mail.AuthenticationFailedException 這裏是我的代碼 如何到reslove這個問題我在忘記密碼電子郵件發送時出現以下錯誤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);
}
}
通過發送正確的用戶/密碼對? –