使用google smtp以编程方式发送电子邮件

时间:2013-07-25 07:30:05

标签: java email networking smtp gmail

美好的一天SO人!

我正在尝试使用gmail smtp服务器通过java代码发送电子邮件很长一段时间了,我仍然不幸获得成功。我尝试执行此tutorial

中的代码

我得到了一个例外。以下是日志跟踪:

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

我已经搜索了连接异常错误,我尝试了一些建议:

  1. ping smtp.gmail.com - >成功。
  2. telnet smtp.gmail.com'port' - >不成功。我试过了465和587
  3. 网络上还有什么需要做的吗?请帮我解决这个问题。提前谢谢。

0 个答案:

没有答案