JavaMail works inside Eclipse but not outside

M

Magnus Warker

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
 
A

Andrew Thompson

Magnus Warker wrote:
...
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?

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.

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1
 
N

Nigel Wade

Magnus said:
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.

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?
 
M

Magnus Warker

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
 
A

Andrew Thompson

Magnus Warker wrote:
..
..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.
 
S

subtenante

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

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.
 
N

Nigel Wade

Magnus said:
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

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.
 
M

Magnus Warker

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
 
N

Nigel Wade

Magnus said:
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?

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?
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?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top