IntelliJ Java IDE
The moose likes Tomcat and the fly likes Why jsp can't send javamail? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Reply Bookmark "Why jsp can Watch "Why jsp can New topic
Author

Why jsp can't send javamail?

lyo Yashnoo
Ranch Hand

Joined: Sep 15, 2003
Posts: 50
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

Joined: Sep 15, 2003
Posts: 50
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:
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

Perhaps someone in the Tomcat forum would be more familiar with this.
bear


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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'.
 
IntelliJ Java IDE
 
subject: Why jsp can't send javamail?
 
Threads others viewed
Filters initialized before context is ready
j2ee newbie question about context and lookup
JNDI Question...
Name bound to Context
javaMail error
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture