美好的一天,人们!
我正在尝试使用 gmail smtp 服务器通过 java 代码发送电子邮件已有一段时间了,但我仍然不走运获得成功。我尝试执行本教程中的代码
我得到了一个例外。以下是日志跟踪:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
at javax.mail.Service.connect(Service.java:317)
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 ph.net.poolbeta.emailer.EmailDriver.sendEmailSSL(EmailDriver.java:108)
at ph.net.poolbeta.emailer.EmailDriver.main(EmailDriver.java:27)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:321)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
... 8 more
我用谷歌搜索了连接异常错误,并尝试了一些建议:
- ping smtp.gmail.com --> 成功。
- telnet smtp.gmail.com 'port' --> 不成功。我试过 465 和 587
关于网络还有什么需要做的吗?请帮我解决这个问题。提前致谢。