2013-02-25 108 views
0

嘗試使用JavaMail閱讀郵件時出現此錯誤。請讓我知道如何解決這個錯誤。我已經加入activation.jarmail.jar進入eclipse。使用JavaMail閱讀郵件

DEBUG POP3: server doesn't support TOP, disabling it 
javax.mail.AuthenticationFailedException: Command is not valid in this state. 
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:174) 
at javax.mail.Service.connect(Service.java:291) 
at javax.mail.Service.connect(Service.java:172) 
at library.VerifyEmail.main(VerifyEmail.java:40) 

下面是我想要的代碼:

package library; 

import java.io.IOException; 
import java.util.Properties; 
import javax.mail.Folder; 
import javax.mail.Message; 
import javax.mail.MessagingException; 
import javax.mail.NoSuchProviderException; 
import javax.mail.Session; 
import com.sun.mail.pop3.POP3Store; 

import java.util.*; 
import javax.mail.*; 
import javax.mail.internet.*; 
import javax.mail.search.SubjectTerm; 
import javax.activation.*; 
import java.io.*; 
public class VerifyEmail { 
public static void main(String[] args) throws Exception { 
    // SUBSTITUTE YOUR ISP's POP3 SERVER HERE!!! 
    String host = "myhost"; 
    // SUBSTITUTE YOUR USERNAME AND PASSWORD TO ACCESS E-MAIL HERE!!! 
    String user = "myuser"; 
    String password = "mypass"; 

// Get a session. Use a blank Properties object. 
    Session session = Session.getInstance(new Properties()); 
    try { 
     // Get a Store object 
     Store store = session.getStore("pop3"); 
     store.connect(host, user, password); 

     // Get "INBOX" 
     Folder fldr = store.getFolder("INBOX"); 
     fldr.open(Folder.READ_WRITE); 
     int count = fldr.getMessageCount(); 
     System.out.println(count + " total messages"); 

     // Message numebers start at 1 
     for(int i = 1; i <= count; i++) { 
      // Get a message by its sequence number 
      Message m = fldr.getMessage(i); 
     // Get some headers 
      Date date = m.getSentDate(); 
      Address [] from = m.getFrom(); 
      String subj = m.getSubject(); 
      String mimeType = m.getContentType(); 
      System.out.println(date + "\t" + from[0] + "\t" + 
           subj + "\t" + mimeType); 
     } 

    }catch (MessagingException ioex) { 
     ioex.printStackTrace(); 
    } 
} 
} 
+1

試試這個props.setProperty(「mail.pop3.disabletop」,「true」); – 2013-02-25 05:05:23

+0

@SudhanshuUmalkar,我試過這個,仍然在線程中提到錯誤。 //爲會話創建屬性 屬性props = new Properties(); props.setProperty(「mail.pop3.disabletop」,「true」); – tester 2013-02-25 05:55:44

回答

0

根據microsoft對於Exchange 2010,默認情況下,服務器將需要爲POP3客戶端使用SSL。 沒有SSL服務器響應 「ERR命令無效在這種狀態下。」

下面介紹如何使用JavaMail與SSL - Javamail and Gmail Pop3 SSL

0

DEBUG POP3:服務器不支持TOP,禁用它 這個消息可以通過更新Java郵件罐子版本1.4.4

2

是禁用當你得到javax.mail.AuthenticationException這意味着你的應用A n無法對郵件服務器進行身份驗證。

一個可能的原因可能是客戶機密鑰庫中缺少郵件服務器的SSL證書。