• Post Reply Bookmark Topic Watch Topic
  • New Topic

Weird Behaviour of javax.mail  RSS feed

 
Bhawana Gupta
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing code to send an email using java mail API. It has an attached excel sheet.
I have put mail sending code say SendMail.java in separate file and calling it fom a jsp when a button is clicked by user.
for testing purpose i had put a main method in SendMail.java which is sending mail pefectly well.

However when i actually execute my code, click on button, i get below exception:



below is my code:



and here is jsp i am calling from:



In addition, i tried to telnet my mail host ...
it connect successfully there ....


please help me get rid of this.....
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So port 25 on the machine called "myhost" is reachable from the machine where this code runs?

What happens if you execute "telnet myhost 25" in your console?
 
Bhawana Gupta
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
myhost is the mailhost name. I have replaced original name with dummy here.
When i
telnet myhost 25
on windows console, it connects saying mail service ready and waits for further commands...


Also i have mentioned above, when i execute my main method, my code is working just fine....

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your SendMail.java tool also work on the machine where Tomcat is running on? Perhaps there is a networking issue on that machine and not yours. If so, contact your network administrator. If you can ping the mailhost the problem may also lie in your virus scanner software. McAfee is notorious for blocking mail connections by default (to prevent worms from mass mailing).
 
Bhawana Gupta
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TOMCAT is running on same machine on which code is being executed....
its development phase...
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Properties properties = System.getProperties();

Dump out what properties are being picked up when that code is run from within Tomcat. It might be possible that some system property setting in Tomcat runtime might be interfering with the mail session creation.
 
Anuj Sharma R
Greenhorn
Posts: 28
1
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it works fine as a standalone, it seems to be pointing to some problem with Tomcat. How about trying to add the property "-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses" to your Tomcat startup configuration and see if that helps?

Let us know how it goes.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also set various debugging flags to generate more output that may be helpful, like "mail.debug" and "java.security.debug". See http://www.oracle.com/technetwork/java/faq-135477.html#debug
 
Bhawana Gupta
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Anuj

I added

to my tomcat launch configurations
and it started to work
 
Anuj Sharma R
Greenhorn
Posts: 28
1
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good to hear that Bhawana. Glad that it worked.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!