我在阅读pop3邮件时遇到异常

时间:2012-10-08 10:29:55

标签: java javamail

我在阅读pop3邮件时遇到问题

我的代码非常简单..

Properties objServerProp = new Properties();
objServerProp.setProperty("mail.transport.protocol", "pop3");
objServerProp.setProperty("mail.host", "xxx.xx-ip.org");
objServerProp.put("imap.mail.port", "110");
objServerProp.put("imap.mail.auth", "true");

Session  objSession = Session.getDefaultInstance(objServerProp, null);
Store instStore = objSession.getStore("pop3");
instStore.connect("xxx.xx-ip.org", Integer.valueOf(110), "id", "pwd");
Folder  objFolder = instStore.getFolder("inbox");
objFolder.open(Folder.READ_WRITE);
int count = objFolder.getMessageCount();

 Message objMessage = objFolder.getMessage(1);
 System.out.println("objMessage is :: "+objMessage);
 System.out.println("  message contenttype :: " + objMessage.getContentType());

当我在消息对象上调用任何方法(如:getContentType())时,我得到的是异常,,,

,消息对象正好

objMessage is :: com.sun.mail.pop3.POP3Message@37d8d2

例外情况如下......

javax.mail.MessagingException: error loading POP3 headers;
  nested exception is:
    java.io.IOException: Unexpected response: 
    at com.sun.mail.pop3.POP3Message.loadHeaders(POP3Message.java:467)
    at com.sun.mail.pop3.POP3Message.getSize(POP3Message.java:106)
    at in10sbouncemailtracker.BMTServer.checkBouncedMails(BMTServer.java:232)
    at BMTMain.main(BMTMain.java:18)
Caused by: java.io.IOException: Unexpected response: 
    at com.sun.mail.pop3.Protocol.simpleCommand(Protocol.java:361)
    at com.sun.mail.pop3.Protocol.multilineCommand(Protocol.java:373)
    at com.sun.mail.pop3.Protocol.top(Protocol.java:271)
    at com.sun.mail.pop3.POP3Message.loadHeaders(POP3Message.java:451)
... 3 more

1 个答案:

答案 0 :(得分:0)

如JavaMail FAQ中所述,turn on session debugging。协议跟踪将显示意外响应的内容。您还应该查看properties described in the com.sun.mail.pop3 package javadocs,其中一些可能对解决服务器中的错误很有用。