Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java mail server verification.

 
U Kvistborg
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am wondering if I am the only one with this specific problem, I whant to check if my smtp host is up and running before I attempt to send an email. Or is it better to see if I get an exception and then handles this ?
I have 3 different smtp hosts I can use, but I would preffer to test if they are running and ready to send my emails before I do it instead of using the exceptions. So my question is how do I do this ?
I did try InetAddress.getByName("w5.company.com").isReachable(1000) but they responds even if my smtp host is down, there are some webhosting here aswell.
 
U Kvistborg
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I even tried this one:
for(int i = 0 ; i<=65535;i++){
InetSocketAddress inet = new InetSocketAddress("w3.company.com", i);
System.out.println("Port " + i + " open " + inet.isUnresolved());
}

And no ports on the server where unresolved, but I know it does not listen to evet port in the range 0-65535

So again how can I detmine that my mail server is listening on the specific smtp port ?
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The isUnresolved method only resolves the address - not the port. You'll have to actually open a connection to the InetSocketAddress to find out if it's open. Usually you can focus on port 25 only for SMTP servers.
 
U Kvistborg
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what you are telling me is that I just aswell could try to send the message, and then see if it fails rather than doing a check for if the port is listening.
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was more talking about making a simple Socket connection to port 25, which will fail if there is no (mail) server running (on that port).
 
U Kvistborg
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help,

Currently trying all sorts of stuff I never really did before, being the only person on a project, that gets to use what ever I like as long as it lives up to the requerenments :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic