我正在尝试使用imap协议连接到james服务器,但我遇到以下异常:
Exception in thread "main" javax.mail.MessagingException: Network is unreachable: connect;
nested exception is:
java.net.SocketException: Network is unreachable: connect
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:611)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at mail.main(mail.java:112)
Caused by: java.net.SocketException: Network is unreachable: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(PlainSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:267)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:277)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:107)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:103)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:578)
... 3 more
James Server已经在运行,我没有得到上述异常的原因。这是因为詹姆斯不支持这个协议还是有其他原因?
这是Javamail应用程序的源代码,它试图连接到James Server:
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class mail{
public static void main(String[] argts){
try {
Properties props=new Properties();
props.put("mail.host", "127.0.0.1 ");
props.put("mail.smtp.auth","true");
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("blue", "blue");
}
});
int Spam=0;
Store store=session.getStore("imap");
store.connect("localhost", "red", "red");
Folder folder=store.getFolder("IMAPFolder");
Folder folder1=store.getFolder("Spam");
boolean b=folder1.create(Spam);
System.out.println(b);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}
答案 0 :(得分:2)
快速检查是否只需使用telnet即可与IMAP服务器通信:
telnet localhost 143
如果没有连接,那么James不会发布IMAP连接(假设是标准的IMAP端口)。
我从下面看到你正在使用James 2.x. This link表示不支持IMAP。
答案 1 :(得分:0)
看起来更像网络配置错误(可以ping通) 检查127.0.0.1是否设置正确(并删除该空格)