Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

JavaMail works inside Eclipse but not outside

Thread view: 
Magnus Warker - 19 Apr 2007 04:25 GMT
Dear group,

my program sends mail to some address using a specific mail server.

When running or debugging the program inside Eclipse, it works fine.

When running it outside Eclipse on the same machine (Windows XP), I receive
a MessagingException, saying that the mail server is not reachable.

Testing this with "telnet <mailserver> 25" also results in an error.

I cannot explain this. Can anyone help?

Thank you,
Magnus
Andrew Thompson - 19 Apr 2007 06:22 GMT
...
>When running or debugging the program inside Eclipse, it works fine.
>
[quoted text clipped - 4 lines]
>
>I cannot explain this. Can anyone help?

I do not fully understand the meaning of the telnet bit,
but for the Java side of it, it might be possible there
is a security sandbox applied to the program.  More
details of the program and code might be required, to
take it further.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Nigel Wade - 19 Apr 2007 09:38 GMT
> Dear group,
>
[quoted text clipped - 4 lines]
> When running it outside Eclipse on the same machine (Windows XP), I receive
> a MessagingException, saying that the mail server is not reachable.

Do you have any Proxies setup in Eclipse?
What transport are you using in your mail client code, is it SMTP to port 25?

> Testing this with "telnet <mailserver> 25" also results in an error.

That doesn't necessarily mean very much. Mail transports may use the MX record
for the mail server you attempt to connect to. That may well not be the same
hostname as the A record. What is the MX record for the mail host you are
using?

> I cannot explain this. Can anyone help?
>
> Thank you,
> Magnus

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Magnus Warker - 19 Apr 2007 18:31 GMT
Dear Nigel and Andrew,

thank you for giving me tips about that.

Well, my java application should monitor a server process and send mail as
soon as the server process does not work anymore.

I just recognized that the mail functionality works when running the program
inside eclipse and does not when run outside eclipse, on the same machine.

As I was told today, access to the mail server via SMTP:25 is denied for
such workstations as the one I tested my application. So this is the reason
why "telnet <mailserver> 25" does not result in a connection. (I just
tested it with this telnet command, just to test if access is possible from
my machine at all).

But what still works and always worked is running the same application on
the same machine inside eclipse. The only difference is that outside
eclipse there is a jar file for the application, several jar files for the
libraries, and a batch file that calls "java -jar myapp.jar". But outside
eclipse I get the error that the mail server is not reachable.

I did not find any proxy settings in my eclipse installation.

In fact, the application works inside eclipse and does not outside. But what
is the difference???

Thank you,
Magnus
Andrew Thompson - 20 Apr 2007 02:38 GMT
..
>..The only difference is that outside
>eclipse there is a jar file for the application, several jar files for the
>libraries, and a batch file that calls "java -jar myapp.jar".

This would not invoke the extra security that I first
thought might be blocking the attempt outside
Eclipse.  I'm out of ideas on this one, sorry.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Nigel Wade - 20 Apr 2007 10:21 GMT
> Dear Nigel and Andrew,
>
[quoted text clipped - 25 lines]
> Thank you,
> Magnus

Please tell us the exact exception which is thrown. Also, could you answer my
question as to what is the message transaction type. Since direct access to the
mail server port 25 is blocked it cannot be simple SMTP. Is is using the mail
submission port or some other mechanism.

Are you absolutely sure that it is connecting to the host which you really think
it is? You mentioned that the exception indicates the host is not reachable,
which doesn't make sense if it's the same host as is accessed when run within
Eclipse. Use a network capture/analysis tool (such as Wireshark) to be sure.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Magnus Warker - 20 Apr 2007 17:30 GMT
Dear Nigel & subtenante,

I just called "java -jar myapp.jar", without giving the complete path to the
java interpreter binary file. After subtenantes posting I found out that
there is a java.exe located in c:\Windows\System32. This is different from
my JDK 1.5.0 and JRE 1.5.0. In eclipse there is only the JRE 1.5.0
installed.

So I tested PathTo\JRE1.5.0_07\bin\java and I was sure that it would work
now. But it did not! :-(
I also tested PathTo\JDK1.5.0_07\bin\java and
PathTo\JDK1.5.0_07\jre\bin\java (what's the difference?), but nothing
worked!

Within eclipse, the application works perfectly, i. e. it can send mail.

Here is the exception I receive when the application wants to send mail:

javax.mail.MessagingException: Could not connect to SMTP host:
post.mydomain.de, port: 25;
  nested exception is:
        java.net.SocketException: Software caused connection abort: connect
        at
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1282)
        at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
        at javax.mail.Service.connect(Service.java:275)
        at javax.mail.Service.connect(Service.java:156)
        at javax.mail.Service.connect(Service.java:105)
        at javax.mail.Transport.send0(Transport.java:168)
        at javax.mail.Transport.send(Transport.java:98)
        at utl.mail.Mailer.send(Mailer.java:66)
        at utl.mail.Mailer.sendMail(Mailer.java:97)
        at utl.mail.Mailer.sendMail(Mailer.java:116)
        at pms.office.Monitor.report(Monitor.java:66)
        at pms.office.Monitor.execute(Monitor.java:105)
        at pms.Application.run_mon(Application.java:143)
        at pms.Application.run(Application.java:155)
        at pms.Application.main(Application.java:200)
Caused by: java.net.SocketException: Software caused connection abort:
connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:516)
        at java.net.Socket.connect(Socket.java:466)
        at
com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:232)
        at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
        at
com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1250)
        ... 14 more

I ist possible that JavaMail behaves differently within eclipse?

> Are you absolutely sure that it is connecting to the host which you really
> think it is?

Well, I used *one* host, which was hardcoded within the code, and the same
code works within eclipse and does not outside eclipse. My code
(utl.mail.Mailer.send) just calls JavaMail code. I cannot see what is
happening inside JavaMail. However, when I run the application (inside or
outside eclipse), is there a simple method to verify the network operations
that take place?

Thanks,
Magnus
Gordon Beaton - 20 Apr 2007 18:50 GMT
> is there a simple method to verify the network operations that take
> place?

Get Wireshark.

/gordon

--
Nigel Wade - 23 Apr 2007 09:39 GMT
> Dear Nigel & subtenante,
>
[quoted text clipped - 53 lines]
>
> I ist possible that JavaMail behaves differently within eclipse?

I don't see how it could unless Eclipse changes its environment somehow, hence
the question regarding proxies. If, as you said above, you are denied access to
the SMTP server on port 25 I would reverse the question. How is Eclipse able to
connect to a host on port 25 which your network admins. claim is firewalled? Is
it really connecting to the host and port you think it is?

>> Are you absolutely sure that it is connecting to the host which you really
>> think it is?
[quoted text clipped - 5 lines]
> outside eclipse), is there a simple method to verify the network operations
> that take place?

As I said, get Wireshark. Use it to capture the packets being sent when you run
your application in Eclipse. Analyse them to see what it really going on. Do
the same when you run your application outside of Eclipse. Look at both
analyses and try to determine the difference.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

subtenante - 20 Apr 2007 05:37 GMT
>Dear group,
>
[quoted text clipped - 11 lines]
>Thank you,
>Magnus

Hi, it might not help you, but in my case i have three versions of the
JRE installed. Do you have only one ? If you have several of them,
maybe the one selected in Eclipse is not the same that is launching
your application outside of it.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.