tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From albrecht andrzejewski <>
Subject get a strange cast error with using the tomcat mail ressource
Date Sun, 11 Feb 2007 22:24:43 GMT

Hello all,

I hope i will not pollute the list, but i'm affraid of being faced  
with a bug :-(

I have to send a mail with tomcat.
I followed the instructions of the tomcat documentation, corresponding  
my version (5.5).

Using this code:

  public static String sendMail(String destinataire, String login){

         Session session = null;
         try {
             Context initCtx = new InitialContext();
             Context envCtx = (Context) initCtx.lookup("java:comp/env");
line 36     session = (Session) envCtx.lookup("mail/MonMail");
             //session = envCtx.lookup("mail/MonMail");
         } catch (NamingException ex) {
               System.out.println("erreur au lookup");
            return ex.getMessage();

I have the following error that i really dislike :

java.lang.ClassCastException: javax.mail.Session cannot be cast to  
         at utils.MailHelper.sendMail(

I use the netbeans 5.5 bundled tomcat server (v 5.5.17) on the 1.6  
java version (but source level set to 1.5).

Do you think it's me ? Or a bug of the IDE ? or a bug of tomcat ?

I previously used this code with the same config in a successful way  
with another tomcat 5.5 server.

I'm getting crazy with this awful and strange cast error :-(
If only someone could help...

I join the web.xml tag:

             Resource reference to a factory for javax.mail.Session
             instances that may be used for sending electronic mail
             messages, preconfigured to connect to the appropriate
             SMTP server.

and my server.xml


and my context.xml

  <Resource name="mail/MonMail" auth="Container"

Hope to hear soon from the list about this problem :-(
Best regards.

Ce message a ete envoye par le serveur IMP de l'EMA.

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message