Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:     smtp.west.cox.net, port: 25;
nested exception is:  java.net.SocketException: Network is unreachable: connect

Here is the code:

Session session = Session.getInstance(props, null);
MimeMessage msg = new MimeMessage(session);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, props.getProperty("mail.to", "me@mine.com"));
msg.setSubject(mySubject);
msg.setSentDate(new Date());
msg.setContent(sBuf.toString(), "text/html");
Transport.send(msg);

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
add comment

1 Answer

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 smtp.west.cox.net machine. This could be due to one of several reasons:

  • Windows machine can't resolve smtp.west.cox.net to an IP (unlikely given the error message)
  • Windows machine has no route to that server's IP
  • Server smtp.west.cox.net 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
add comment

Your Answer

 
discard

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.