Unknown SMTP host - java

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

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.

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

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.

Specially for AIX or Linux OS environment,
We need to add the hostname in the etc/hosts file.. to sole this.
Windows operating system , this may work on Windows system as there is no strict security check however AIX or Linux must add host name to etc/hosts file in order for ping the SMTP server.
avoid doing this may lead Unknown host issue

Related

Java JDB: ERROR: transport error 202: gethostbyname: unknown host

I have a very similar error message to this post; however, the solution on that same post did not work for me. Editing the host file my adding in 127.0.0.1 my-host-name to my hosts file (per solution in linked thread) did nothing for me unfortunately.
After "run" in JDB, I get the following error message:
Initializing jdb ...
run run QuadtreeBitmap VM start exception: VM initialization failed for:
/Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/java
-Xdebug -Xrunjdwp:transport=dt_socket,address=Patricks-iMac.local:50547,suspend=y
QuadtreeBitmap
ERROR: transport error 202: gethostbyname: unknown host ERROR: JDWP
Transport dt_socket failed to initialize, TRANSPORT_INIT(510) JDWP
exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized
[debugInit.c:730]
Fatal error: Target VM failed to initialize.
I am using MacOS and trying to launch JDB directly through the terminal (and not through Eclipse or any other IDE).
In my case problem was related to Java 8. I used Java 9+ syntax for remote debugger:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
While for Java 8 you cannot use address in format *:port it suppose to be:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
The jvm is trying to open the dt_socket at host Patricks-iMac.local, port 50547 but needs first to resolve that host name to an IP address. DNS lookup will fail since it's a dummy hostname assigned to a private address and DNS servers usually don't know about them unless a sysadmin has configured them (companies use to do that). There are two solutions for this:
Add the hostname mapping on hosts file keeping other names configured for that IP
127.0.0.1 localhost Patricks-iMac.local
Configure the dt_socket by IP address without touching hosts file (recommended)
-Xrunjdwp:transport=dt_socket,address=127.0.0.1:50547
A word on networking troubleshooting:
unknown host means DNS problems, TCP connection did not start at all because an IP address was not available.
host unreachable means TCP connectivity problems, an IP is known but not reachable because of firewall, routing or other problems. ping to that IP will fail.
port unreachable means TCP connectivity problems, the IP is reachable but the port is not because of firewalls, service is down, etc. ping to the IP will work but connections to that port will still fail.
A word on security
The following syntaxes imply a security risk since the debug port will be exposed on all interfaces. Mitigation measures might be good to apply.
address=*:5005
address=0.0.0.0:5005
address=5005 (java 8, binds to loopback interface on java 9+)
May network admins made some changes in the meantime. Some firewall stuff. Problem is that Eclipse tries to establish connection to JVM at "localhost" (and some random port). You can try this solution.
Unable to debug in Java with eclipse

SmbException: A duplicate name exists on the network: how to prove that a few servers have the same DNS name

Need your advice about the following:
We try to get file from another server in our local network by SMB
When we call server by IP everything works file
When we call server by DNS name we get an exception: jcifs.smb.SmbException: A duplicate name exists on the network
I googled the similar questions and found that it could happen when a few servers have the same DNS name.
Could you please advise me how to prove it to our network administrators? Because they say that it’s impossible and every server has the only DNS name in our local network.
Thank you!
You may also have a server which is registered under 2 different domains, and a program which tries to access this server without mentioning a domain.
If such is the case, if you enter:
nslookup <server>.<expected domain>
you may get:
Non-authoritative answer:
Name: <server>.<expected domain, for instance your company's domain>
Address: <IP>
And if you enter:
nslookup <server>
(note that you did not mention any domain) you may get:
Non-authoritative answer:
Name: <server>.<UNexpected domain #2>
Address: <IP>
If this is the case, we have to unregister your server from the unexpected domain and everything should go back to normal.

Connecting to derby via I.P. Address fails

When I print the I.P. address of the system using InetAddress.getLocalHost(), I get user-VAIO/192.168.1.3 . Now, when I connect to derby using jdbc:derby://localhost:1527/mydatabase;create=true, it connects without any errors but when I connect the same using jdbc:derby://192.168.1.3:1527/mydatabase;create=true, it fails giving me the following exception:-
java.net.ConnectException : Error connecting to server 192.168.1.3 on port 1527 with message Connection refused: connect.
Any help will be appreciated.
When you start your Derby Network Server, you provide a value for the '-h' argument. You might not realize you are doing this, if you are using the packaged StartNetworkServer.bat file, but look inside the batch file, and you will see the -h argument there.
The batch file comes provided with the syntax '-h default' when you download Derby from the Apache website.
But you can change that, to say, for example, '-h 192.168.1.3', and then your Derby Network Server will accept connections that specify 'jdbc:derby://192.168.1.3/my/database'.
Note that if you want to accept such connections from other computers on the network, you will also have to adjust your Windows Firewall rules, as by default it will prevent such connections.

NoRouteToHostException on client or server?

I am getting
Caused by: java.net.NoRouteToHostException: No route to host
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 com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:564)
at sun.reflect.GeneratedMethodAccessor638.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:130)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
javadoc says
Signals that an error occurred while attempting to connect a socket to
a remote address and port. Typically, the remote host cannot be
reached because of an intervening firewall, or if an intermediate
router is down.
Is this error on client side or remote side or it can be either of these?
Basically it says that your client cannot connect to the server due to the address is inaccessible from the client machine.
Please check that the address you are connecting to is accessible, either via ping command in your Command Prompt (Windows) or terminal (Unix-based):
ping <address>
or if it's a web server you can try to check it in your web browser.
The ping command is helpful for me in most cases, since I would know why exactly I can't connect to the address. It can be a mistyped address or like the javadoc suggests, problem with firewall.
Either. It could be a firewall on the client machine blocking outgoing calls or somewhere at the other end.
It may be possible the ping will provide responses, but the application may still fail to connect.
If that is the case, I would suggest using telnet to try and connect to the host using the desired port, telnet host.address port
If the connection is refused then the port on the host will need to be allowed. It that succeeds, but the application still won't connect:
Verify the address:port being used in your application are the same as those used in the telnet test.
It may be a local port on the client blocking the connection, in which case you would need to allow the port on the client
In my case it was solved like this:
1 - Clear the cache with 'yarn cache clean' or 'npm cache clean --force'
2 - after that reboot the pc.
If you clear the cache but do not reboot, the data will still be stored 'somewhere' on the network, so the port will not connect, it is still busy.
After restarting it connects smoothly.
I hope I was helpful!
I had the same issue, and resolve it by disabling the firewall on both sides :
systemctl disable firewalld
service firewalld stop
I had the same issue, I did run iptables flush on host server, this fixed the issue.
# iptables --flush

UnknownHostException accessing service on virtualBox

Oracle NoSQL is a database that should be hosted on Linux, so I have a virtual Ubuntu running in Oracle VM VirtualBox.
When you run the KvStore for Oracle NoSQL it uses port 5000 for the database, and 5001 for the admin console. From my pc, I can access the admin console running on the linux virtual machine like so:
http://192.168.0.25:5001/
Where 192.168.0.25 is the inet addr I get from the linux machine's ifconfig command.
However, if I try to connect to the database from java, passing java the host and port number like so:
KVStoreConfig kvconfig = new KVStoreConfig("kvstore", "192.168.0.25:5000");
I get the following error:
Exception in thread "main" oracle.kv.FaultException: Could not contact any RepNode at: [192.168.0.25:5000] (11.2.2.0.26)
Fault class name: oracle.kv.KVStoreException
at oracle.kv.KVStoreFactory.getStore(KVStoreFactory.java:123)
at nosql.Test.main(Test.java:18)
Caused by: oracle.kv.KVStoreException: Could not contact any RepNode at: [192.168.0.25:5000]
at oracle.kv.impl.util.TopologyLocator.getInitialTopology(TopologyLocator.java:226)
at oracle.kv.impl.util.TopologyLocator.get(TopologyLocator.java:85)
at oracle.kv.impl.api.RequestDispatcherImpl.<init>(RequestDispatcherImpl.java:285)
at oracle.kv.KVStoreFactory.getStore(KVStoreFactory.java:118)
... 1 more
Caused by: java.rmi.UnknownHostException: Unknown host: coraythan-VirtualBox; nested exception is:
java.net.UnknownHostException: coraythan-VirtualBox
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:616)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:128)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy0.getSerialVersion(Unknown Source)
at oracle.kv.impl.util.registry.RemoteAPI.<init>(RemoteAPI.java:60)
at oracle.kv.impl.rep.admin.RepNodeAdminAPI.<init>(RepNodeAdminAPI.java:63)
at oracle.kv.impl.rep.admin.RepNodeAdminAPI.wrap(RepNodeAdminAPI.java:70)
at oracle.kv.impl.util.TopologyLocator.getInitialTopology(TopologyLocator.java:191)
... 4 more
Caused by: java.net.UnknownHostException: coraythan-VirtualBox
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
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 oracle.kv.impl.util.registry.ClientSocketFactory.createSocket(ClientSocketFactory.java:300)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 14 more
I can get that to work fine when I host a KvStore on my normal computer and try to connect to it like that (using the normal computer's IP address) with java.
Another weird thing is that if I'm in the virtual machine, I can access the admin with this:
coraythan-virtualbox:5001
But if I try to do that from my main computer it gives me a "could not find" error.
I have tried changing my java connection to coraythan-virtualbox:5000, but that also doesn't work.
Does anyone know what I'm doing wrong here? Thanks!
The issue was that the linux computer did not automatically register its network name with my company's network. I had to have the network admin manually add a network name for the computer. The KVStore requires using the network name it seems.
You are making a socket using named address, that is DNS doesn't know such name. Try change it to IP address.
UnknownHostException
Thrown to indicate that the IP address of a host could not be
determined.

Categories

Resources