通过javamail连接错误

发布于 2024-08-06 02:40:37 字数 2313 浏览 7 评论 0原文

我正在尝试使用 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 服务器已在运行,我不明白上述异常的原因。这是因为 James 不支持这个协议还是有其他原因?

以下是 Javamail 应用程序的源代码,该应用程序正在尝试连接到 James 服务器:

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();
        }


        }

    }

}

I'm trying to connect to james server using imap protocol, but I'm getting following exception:

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

The James Server is already running, I don't get the reason of the above exception. Is this because James doesn't support this protocol or there any other reason?

Here's the source code of Javamail application, which is trying to connect to 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();
        }


        }

    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山有枢 2024-08-13 02:40:37

快速检查一下您是否可以仅使用 telnet 与 IMAP 服务器通信:

telnet localhost 143

如果无法连接,则 James 不会发布 IMAP 连接(假设使用标准 IMAP 端口)。

我从下面看到您正在使用 James 2.x。 此链接表明不支持 IMAP。

A quick check is to see if you can talk to your IMAP server simply by using telnet:

telnet localhost 143

and if this doesn't connect, then James isn't publishing an IMAP connection (assuming the standard IMAP port).

I see from the below that you're using James 2.x. This link suggests that IMAP isn't supported.

忘你却要生生世世 2024-08-13 02:40:37

看起来更像是网络配置错误(你能 ping 通它吗)
检查 127.0.0.1 是否设置正确(并删除该空间)

Looks more like a network configuration error (can you ping it)
Check that 127.0.0.1 is setup correctly (and get rid of that space)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文