wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "mail/session" Watch "mail/session" New topic
Author

mail/session

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.setSubject(subject);
message.setContent(content, "text/plain");
// Send our mail message
Transport.send(message);
// From web.xml file
<resource-ref>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
// From server.xml file
<Resource name="mail/Session" auth="Container"
type="javax.mail.Session"/>
<ResourceParams name="mail/Session">
<parameter>
<name>mail.smtp.host</name>
<value>localhost</value>
</parameter>
</ResourceParams>


http://www.goodercode.com
SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mail/session
 
Similar Threads
Name bound to Context
Tomcat 6.0 Can't find SMTP host setting in Context.xml file
javax.mail.Session and DataSource (Apache Tomcat)
javax.mail.Session and DataSource (Apache Tomcat)
How to re-config "mail.host.smtp","localhost" in tomcat 5.0.28