Unknown SMTP host

34,163

Solution 1

This looks like a failure in your name service. The JDK isn't able to look up the host name to find its internet address. Since this works sometimes and not others, it looks like an intermittent failure of the name service. The name service failure could be due to some failure in your local operating system, or it could be due to some network failure communicating with your DNS server or other name service server, or it could be a failure in that DNS server or name service server itself. Determining the exact cause of the failure will require some debugging. Note that the JDK caches the results of name server lookups for some time so you'll need to factor that into your debugging.

Solution 2

Also make sure there is no space at the end of smtp hostname eg. mail.google.comSPACEHERE . Surprisingly this happened to me and finally after removing this space there was no complain about smtp host . Email was successfully sent

Solution 3

Set for host the ip address of the domain name instead of the domain name. use nslookup mail.mydomain.co.uk on cmd to find the ip address. It worked for me.

Share:
34,163
AL̲̳I
Author by

AL̲̳I

Updated on February 01, 2020

Comments

  • AL̲̳I
    AL̲̳I over 4 years

    I am running a Java web application using tomcat to send generated reports via emails to the users. I am able to send the emails but after few hours the server stops sending emails, with the following error.

    javax.mail.MessagingException: Unknown SMTP host: mail.mydomain.co.uk;
    nested exception is:
    java.net.UnknownHostException: mail.mydomain.co.uk
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1970)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
    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 com.turnkey.email.SendEmail.sendMail(SendEmail.java:119)
    at com.turnkey.thread.CommunicationThread.run(CommunicationThread.java:399)
    Caused by: java.net.UnknownHostException: mail.mydomain.co.uk
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:195)
    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:319)
    at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1938)
    ... 8 more
    

    After some time the server starts sending emails again.

    Can anyone tell me what could be the problem. And how do I solve this problem?

    Thanks