2015-05-17 34 views
0

我在忘記密碼電子郵件發送時收到以下錯誤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); 
    } 



} 
+1

通過發送正確的用戶/密碼對? –

回答

1

確實在這裏有適當的參數值:

transport.connect("smtp.gmail.com", 587, "myemailaddress", "password"); 

,此外,as of this,端口的動態IP地址是不同的,請先閱讀這個介紹。

+0

是的,我確定有一個合適的參數值 – Aravind

+0

'AuthenticationError'意思是:用戶名/密碼錯誤或者您被其他方式拒絕訪問。你不能與這個錯誤信息爭論... –

+0

謝謝你的迴應,我明白了,非常感謝你 – Aravind

相關問題