• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Weird Behaviour of javax.mail

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TOMCAT is running on same machine on which code is being executed....
its development phase...
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 28
1
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good to hear that Bhawana. Glad that it worked.
 
reply
    Bookmark Topic Watch Topic
  • New Topic