1

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?

Oldskool
  • 2,025
  • 1
  • 16
  • 27
user1071914
  • 183
  • 1
  • 3
  • 10
  • 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

1 Answers1

1

"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)
John
  • 9,070
  • 1
  • 29
  • 34
  • 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