JavaMail Hotmail GetFolderList

时间:2012-01-06 19:32:09

标签: java javamail pop3 hotmail

除了收件箱之外,我想查看我的Hotmail帐户中的其他文件夹。

String host = "pop3.live.com";
String username = "peepants@hotmail.com";
String password = "peepantspants";
Properties pop3Props = new Properties();
pop3Props.setProperty("mail.pop3s.port",  "995");
Session session = Session.getInstance(pop3Props, null);
Store store = session.getStore("pop3s");
store.connect(host, 995, username, password);

Folder folder = store.getFolder("INBOX");    //this works fine
folder.open(Folder.READ_WRITE);

Folder[] f = store.getDefaultFolder().list("*");
for (int i = 0; i < f.length; i++ )
    System.out.println( f[i].getFullName() );    //this only prints INBOX

Folder ofolder = store.getFolder("MyOtherFolder");    //this doesn't work
ofolder.open(Folder.READ_WRITE);

Message messages[] = folder.getMessages(); 
folder.copyMessages(new Message[]{messages[0]}, ofolder);    //this doesn't work

除了收件箱,我无法进入任何其他文件夹。

store.getFolder("MyOtherFolder")

抛出以下错误

Exception in thread "main" javax.mail.FolderNotFoundException: folder is not INBOX
    at com.sun.mail.pop3.POP3Folder.open(POP3Folder.java:199)

1 个答案:

答案 0 :(得分:1)

你做不到。 POP3协议仅支持单个邮箱。据我所知,Hotmail仍然不支持任何其他标准协议,如IMAP,允许访问其他邮箱。