File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes mail/session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "mail/session" Watch "mail/session" New topic


Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
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">
SCJP 1.4
I agree. Here's the link:
subject: mail/session
It's not a secret anymore!