为什么我会得到这个异常?
此方法给出了收件箱中的电子邮件数量。但它给了我这个例外:
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection timed out: connecterror
-
Session session = Session.getInstance(new Properties());
try {
Store store = session.getStore("pop3");
store.connect("pop.gmail.com" , "username" , "password");
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.READ_WRITE);
int count = fldr.getMessageCount();
System.out.println(count);
} catch(Exception exc) {
System.out.println(exc + "error");
}
This method gives the number of emails in the inbox.But it gives me this exception :
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection timed out: connecterror
-
Session session = Session.getInstance(new Properties());
try {
Store store = session.getStore("pop3");
store.connect("pop.gmail.com" , "username" , "password");
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.READ_WRITE);
int count = fldr.getMessageCount();
System.out.println(count);
} catch(Exception exc) {
System.out.println(exc + "error");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(4)
试试这个:
另请访问此问题
Try this :
Also visit this question
可能是因为服务器拒绝连接。
尝试从“telnet”连接。一旦可以连接,那么您应该能够从 Java 程序进行连接。
以下是一些故障排除提示:
http://www.anta.net/ Misc/telnet-troubleshooting/pop.shtml
https://www-304.ibm.com/support/docview.wss?uid=swg21097014
http://support.microsoft.com/kb/885685
Probably because the server refuses to connect.
Try connecting from "telnet". Once you can connect at all, then you should be able to connect from your Java program.
Here are some troubleshooting tips:
http://www.anta.net/misc/telnet-troubleshooting/pop.shtml
https://www-304.ibm.com/support/docview.wss?uid=swg21097014
http://support.microsoft.com/kb/885685
尝试更改
为
免责声明:我还没有对此进行测试。
Gmail 需要安全的 SSL 连接,而 javax.mail.Service 可能不提供该连接。不过,我认为更可能的解释是您没有连接到正确的端口,因此我明确为 Gmail 的 POP3 服务指定了正确的端口号。
Try changing
to
Disclaimer: I have not tested this.
Gmail requires a secure SSL connection, and maybe javax.mail.Service isn't providing that. I think the more likely explanation, though, is that you're simply not connecting to the right port, so I've explicitly specified the correct port number for Gmail's POP3 service.
尝试遵循“如何使用 gmail 作为 smtp 服务器” 教程。 Google 还有一个配置页面,其中包含您需要的所有设置需要。
Try following a "how to use gmail as an smtp server" tutorial. Google also has a configuration page with all the settings you'll need.