aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes java mail server verification. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "java mail server verification." Watch "java mail server verification." New topic
Author

java mail server verification.

U Kvistborg
Greenhorn

Joined: Oct 14, 2002
Posts: 29
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.


SCJP 1.4/1.5, SCWCD 1.4, SCBCD 1.3
U Kvistborg
Greenhorn

Joined: Oct 14, 2002
Posts: 29
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

Joined: Oct 27, 2005
Posts: 19670
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
U Kvistborg
Greenhorn

Joined: Oct 14, 2002
Posts: 29
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

Joined: Oct 27, 2005
Posts: 19670
    
  18

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

Joined: Oct 14, 2002
Posts: 29
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 :-)
 
 
subject: java mail server verification.