• 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

Why jsp can't send javamail?

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone:

I am writing javamail in jsp using Tomcat.I set the Session in Tomcat console.It is "mail/session". In jsp my code is:
////////////////////////////////////////////////////////////////////////
Context ctx=new InitialContext();
Session session=(Session)ctx.lookup("mail/session");
Message message=new MimeMessage(session);
message.setFrom(new InternetAddress(mailfrom));
But when I click the send mail button,Tomcat report error:
//////////////////////////////////////////////////////////////////////
javax.naming.NameNotFoundException: Name mail is not bound in this Context
But I have set the "session" value in console indeed.
Even I change the code to "Session session=(Session)ctx.lookup("java:comp/env/mail/session");" It also can't work.Tomcat says:"javax.naming.NameNotFoundException: Name java:comp is not bound in this Context"
Why this happen?I found that the situaction happen usually when I use like datasource,Mail.Tomcat isn't steady?
 
lyo Yashnoo
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I send the mail in servlet.But it alway says :"ENCOUNTERED EXCEPTION: javax.naming.NameNotFoundException: Name java:comp is not bound in this Context ".
But I had set the value in Tomcat console.The Tomcat's example:javamail can run property.Have someone come across this problem? :roll:
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps someone in the Tomcat forum would be more familiar with this.
bear
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what console would that be? What does your server.xml file look like?

As an aside, if you're doing this in a JSP, you might want to choose a different variable name than 'session'.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic