1. 程式人生 > >原 java傳送郵箱認證錯誤553 authentication is required

原 java傳送郵箱認證錯誤553 authentication is required

因為專案需要,所以拿了之前釋出的java郵箱demo來修改,地址如下 

http://blog.csdn.net/sun2015_07_24/article/details/50467133,

但是用的時候突然報這個錯誤

他說我的郵箱沒有認證,我很奇怪,以前用的時候不出這錯誤的。現在卻出現的。可能是郵箱伺服器那邊升級還是怎麼了吧。。 
那麼我們解決這個錯誤的方法這麼做。 
錯誤說要我們認證。那我們就認證一下吧。程式碼如下

程式碼總的意思就是校驗一下郵箱的使用者名稱和密碼是否正確

props.put(“mail.smtp.auth”, “true”); 
Authentication authentication = new Authentication(userName, userPwd); 
Session session = Session.getDefaultInstance(props,authentication);

class Authentication extends Authenticator{  
      String username=null;  
      String password=null;  

      public Authentication(){  
      }  
      public Authentication(String username, String password) {  
      this.username = username;  
      this.password = password;  
      }  
      protected PasswordAuthentication getPasswordAuthentication(){
      PasswordAuthentication pa = new PasswordAuthentication(username, password);
      return pa;
      }  
    }