我有以下异常:
javax.mail.MessagingException: Connect failed;
nested exception is:
java.io.IOException: Connect failed
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:106)
at javax.mail.Service.connect(Service.java:234)
at javax.mail.Service.connect(Service.java:135)
at SimpleReceiver.receive(SimpleReceiver.java:50)
at SimpleReceiver.main(SimpleReceiver.java:29)
我怎么解决这个问题?这是代码:
Store store = null;
Folder folder = null;
try {
//Get hold of the default session
Properties props = System.getProperties();
props.put("mail.store.protocol", "pop3");
props.put("mail.pop3.port", "25");
props.put("mail.pop3.host", "admin");
props.put("mail.pop3.auth", "true");
//Session session = Session.getDefaultInstance(props, null);
Session session = Session.getInstance(props);
//Get hold of a POP3 message store, and connect to it
store = session.getStore("pop3");
store.connect("pop3", 25, "admin", "1234");
//Try to get hold of the default folder --
folder = store.getDefaultFolder();
if (folder == null)
throw new Exception("No default folder");
// and its INBOX --
folder = folder.getFolder("INBOX");
if (folder == null)
throw new Exception("No POP3 INBOX");
//Open the folder for read only --
folder.open(Folder.READ_ONLY);
// Get the message wrappers and process them --
Message[] msgs = folder.getMessages();
for (int msgNum = 0; msgNum < msgs.length; msgNum++) {
printMessage(msgs[msgNum]);
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
//Close down nicely --
try {
if (folder != null)
folder.close(false);
if (store != null)
store.close();
} catch (Exception ex2) {
ex2.printStackTrace();
}
}
}
那么为什么会发生以下异常:
javax.mail.MessagingException: Connect failed;
nested exception is:
java.io.IOException: Connect failed
..................................................... ...................................................