Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Java program which uses javax.mail to send an SMTP message. This program WORKS FINE on a Linux box, I want to emphasize that beforehand. When I try this same code on my Windows 7 x64 box, I get this error:

send failed, exception: javax.mail.MessagingException: Could not connect to SMTP host:, port: 25;
nested exception is: Network is unreachable: connect

Here is the code:

Session session = Session.getInstance(props, null);
MimeMessage msg = new MimeMessage(session);
msg.setRecipients(Message.RecipientType.TO, props.getProperty("", ""));
msg.setSentDate(new Date());
msg.setContent(sBuf.toString(), "text/html");

This program pretty much uses defaults for everything. It works fine on another box on the same network. It uses the same settings that I use for my regular mail client, which works fine. There is something on THIS Windows box that is blocking SMTP, but only for Java.

I have Symantec (Norton) 360 installed. Turning it off makes no difference, but rebooting into Safe Mode (which disables almost everything) allows the program to work and send mail just fine.

So, to recap:

  1. The program code works.
  2. The settings are correct.
  3. SMTP works for Windows Mail and is only blocked for Java on this Windows machine.

Before I spend another day tearing things apart and uninstalling/reinstalling, I wondered if anyone had any advice on fixing this?

share|improve this question
Is the Windows firewall enabled? How is it configured? How is the NLA configured? – jscott Dec 28 '12 at 14:33
@jscott - In Windows 7, Windows Firewall delegates control to the 3rd party app (if installed). In this case it is controlled by Norton 360. NLA is set to "Home Network" which should give full access. – user1071914 Dec 28 '12 at 14:49
up vote 1 down vote accepted

"Could not connect to SMTP host" and "Network is unreachable" suggest that the root cause is that your Windows machine cannot connect to the machine. This could be due to one of several reasons:

  • Windows machine can't resolve to an IP (unlikely given the error message)
  • Windows machine has no route to that server's IP
  • Server isn't accepting connections from your Windows server (likely only if your Windows server is coming from a different IP (from the SMTP server's perspective) than your Linux server)
share|improve this answer
The problem turned out to be an IPv4/IPv6 problem. Java tries to use IPv6 if it's available but my ISP doesn't support it. Forcing IPv4 usage solved the problem. – user1071914 Dec 28 '12 at 16:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.