• 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

javax.mail.Session and DataSource (Apache Tomcat)

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to set up DataSource to use javax.mail.Session. And I need help here.

1. I think I configured web.xml correctly.

<resource-ref>
<res-ref-name>mail/MailSession</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

2. How to lookup JNDI is also clear I think

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (javax.mail.Session) envCtx.lookup("mail/MailSession");

3. But I am not sure how to configure server.xml(TOMCAT)

<Resource name="mail/MailSession" auth="Container" ype="javax.mail.Session" mail.smtp.host="sergey"/>

Is it correct way to configure?

Please suggest me where can I go and read more information about java.mail.session with DataSource, may be see some examples, tutorials.


Thank you very much!
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a section on JavaMail Session in this page:
http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html

It might be what you're looking for.
 
Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben, thank you very much for your reply. I think I did it just the same way

<Resource name="mail/MailSession" auth="Container" ype="javax.mail.Session" mail.smtp.host="sergey"/>

but Tomcat stops working if I include this into server.xml... it does not even start up...

oh wait.. may be I need to copy javax.mail jars into tomcat commons folder?
 
Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got tomcat to start up. I did not put JavaMail required jars into it.
But now I get java.lang.ClassCastException: javax.mail.Session when I cast to (Session). Do you have ideas why?


Context initCtx = new InitialContext();
Session session = (Session)initCtx.lookup("java:/comp/env/mail/MailSession");
pop3store = session.getStore("pop3");
pop3store.connect(pop3Server, userName, userPassword);
 
Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it working!
very strange, but it started working after I restarted my IDE. hmmmm I knew I should restart tomcat when I make changes to server.xml but I did not know I should also restart IDE to get it working.

anyways... thank you for your support.
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic