无法连接到SMTP主机:smtp.yahoo.com,端口:25

时间:2012-04-01 06:35:13

标签: java-ee

  

可能重复:
  javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25;

我正在尝试在我的代码中实现邮件工具,但我得到了这个例外。请提出一些解决方案。我是在intellij想法中做的。

javax.mail.MessagingException: Could not connect to SMTP host: smtp.yahoo.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1972)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at SendMail.send(SendMail.java:53)
at SendMailTest.main(SendMailTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:319)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1938)
... 13 more

2 个答案:

答案 0 :(得分:2)

您收到异常是因为主机smtp.yahoo.com在端口25上没有响应(很可能此端口在其防火墙上被永久阻止)。尝试其他SMTP服务器(或您的本地主机)。

答案 1 :(得分:-1)

我认为smtp.yahoo.com是一个无效的smtp字符串。尝试使用此站点上的有效smtp字符串: