我想用java程序发送电子邮件。我得到如下例外

时间:2012-10-12 06:53:32

标签: java email

我遇到了这个例外:

javax.mail.MessagingException: Unknown SMTP host: server.gmail.com;
  nested exception is:
    java.net.UnknownHostException: server.gmail.com
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1280)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
    at javax.mail.Service.connect(Service.java:275)
    at javax.mail.Service.connect(Service.java:156)
    at javax.mail.Service.connect(Service.java:105)
    at javax.mail.Transport.send0(Transport.java:168)
    at javax.mail.Transport.send(Transport.java:98)
    at com.SimpleSendEmail.main(SimpleSendEmail.java:33)
Caused by: java.net.UnknownHostException: server.gmail.com
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
    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:232)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
    ... 7 more

我也包含了所需的jar文件。 请帮我解决这个例外。

2 个答案:

答案 0 :(得分:2)

尝试使用smtp.gmail.com作为主持人。

答案 1 :(得分:0)

你的smtp主机显然是错误的

仅尝试smtp.gmail.com