Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java mail keeping Transport object connected  RSS feed

 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i keep the java mail transport object alive or connected.

I have written this code in a simple class file in a web application : -



the full code being here

and i have commented out the finally block

Now everytime i run this code it takes some time to connect with the mail server
and the line
System.out.println("" + transport.isConnected());
prints a false

How do i retain the object transport as it does gets null and into the block
if(transport == null) {

or the transport object remains connected...

Thanks
Pradyut

 
Shinelin Samuel
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Have the Transport object declared as static. It is advisable to have the SMTP connection code in a static method separated from sendEmail method.


Regards,
Shinelin
 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That solves it...

really i missed out a basic thing... although gave it a thought too....

anyways.... thanks a ton...

Pradyut

 
Pradyut Bhattacharya
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code should be....without any problems but can be good with a function static Transport getTransport() method



Thanks
Pradyut
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!