2010-09-21 155 views
0

我已經編寫代碼來檢查它正在爲gmail工作的電子郵件帳戶& yahoo郵件 但它不適用於hotmail &美國在線。以下是我用過的代碼。如果有任何想法,請幫助。如何檢查電子郵件帳戶是否有效?

我得到以下情況例外,當我通過Hotmail帳戶:

javax.mail.MessagingException: Exception reading response; 
nested exception is: 
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection? 

代碼:

public boolean checkEmailAccountInfo(final String userMailID, 
     final String password, String outgoingMailServer, String portNo) { 

    try { 
     Properties p = new Properties(); 
     // Boolean b = new Boolean(true); 
     p.put("mail.smtps.auth", true); 
     p.put("mail.smtp.user", userMailID); 
     p.put("mail.smtp.host", outgoingMailServer); 
     p.put("mail.smtp.port", portNo); 
     p.put("mail.smtp.starttls.enable", true); 
     p.put("mail.smtp.auth", "true"); 
     p.put("mail.smtp.8BITMIME", "true"); 
     p.put("mail.smtp.PIPELINING", "true"); 
     p.put("mail.smtp.socketFactory.port", 465); 
     p.put("mail.smtp.debug", "true"); 

     p.put("mail.smtp.socketFactory.class", 
       "javax.net.ssl.SSLSocketFactory"); 
     p.put("mail.smtp.socketFactory.fallback", "false"); 
     // create some properties and get the default Session 

     javax.mail.Session session = javax.mail.Session.getInstance(p, 
       new javax.mail.Authenticator() { 
        public PasswordAuthentication getPasswordAuthentication() { 
         return new PasswordAuthentication(userMailID, 
           password); 
        } 
       }); 
     session.setDebug(false); 

     Transport t = session.getTransport("smtp"); 
     t.connect(); 
     boolean isConnected = t.isConnected(); 
     if (isConnected) { 
      t.close(); 
      return true; 
     } 
     return false; 
    } catch (Exception e) { 
     return false; 
    } 
} 
+0

只需發送一封電子郵件並等待,直到您得到他們的回覆:P – GoodSp33d 2010-09-21 07:40:05

+0

您是否確實想直接連接到Hotmail/AOL?也許問題是,Hotmail/AOL不希望你檢查這樣的電子郵件地址... – 2010-09-21 07:51:53

回答

1

你可以試試這個:

p.put("mail.smtp.socketFactory.port", portNo); 

這會工作。我有用其他郵件ID進行測試。

+0

我已經嘗試過了。仍然得到相同的例外。 – 2010-09-21 09:13:23

+0

你不能檢查是否有效的電子郵件地址。郵件API使用主機名稱而不是電子郵件地址檢查服務器IP。 – 2010-09-21 09:59:24

+0

你能舉個例子嗎? – 2010-09-21 10:36:48

相關問題