This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic


Kerry Wilson
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to email from a servlet. but I keep getting a servlet not available. I know it has to do with this code because if it is commented out it will work. (But, will not send an email, of course). The problem appears to with the Session object being read from the context. I have entries from web.xml and server.xml are these correct? Thanks
// Acquire our JavaMail session object
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (Session) envCtx.lookup("mail/Session");

// Prepare our mail message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress dests[] = new InternetAddress[]
{ new InternetAddress(to) };
message.setRecipients(Message.RecipientType.TO, dests);
message.setContent(content, "text/plain");
// Send our mail message
// From web.xml file
// From server.xml file
<Resource name="mail/Session" auth="Container"
<ResourceParams name="mail/Session">
I agree. Here's the link:
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic