2010-01-23 48 views

回答

0

只需使用文檔,它位於sinetfactory的html文件夾中。一切都在那裏。

import com.jscape.inet.imap.*; 
import com.jscape.inet.email.*; 
import com.jscape.inet.imapssl.ImapSsl; 
import com.jscape.inet.mime.*; 
import java.io.*; 

public class ImapSshExample { 
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));; 

    public void getMessages() throws ImapException, MimeException, IOException { 

     ImapSsl imap = new ImapSsl("imap.gmail.com", 993, "username", "password"); 
     imap.connect(); 
     int messageCount = imap.getMessageCount(); 

     for (int i = 1; i <= messageCount; i++) { 
      EmailMessage msg = imap.getMessage(i); 
      System.out.println("-- begin message --"); 
      System.out.println(new String(msg.getMessage())); 
      System.out.println("-- end message --"); 

      System.out.print("ENTER for next message or type QUIT to quit: "); 
      String command = reader.readLine(); 
      if (command.equalsIgnoreCase("quit")) { 
       break; 
      } 
     } 
     imap.disconnect(); 
    } 

    public static void main(String[] args) { 
     try { 
      ImapSshExample example = new ImapSshExample(); 
      example.getMessages(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 
+0

但如何才能獲得新的或未讀郵件。 – 2010-01-24 10:50:17

0

Heeey,在看文檔:)這是你如何能得到新的消息:

// get messages in mailbox 
Enumeration e = imap.getNewMessages(); 

// loop thru all messages in mailbox 
while(e.hasMoreElements()) { 
EmailMessage message = (EmailMessage)e.nextElement(); 
// print out subject, or do what you want 
System.out.println(message.getSubject());