3 Replies Latest reply on Aug 30, 2006 3:09 AM by damijanv

    JavaMail problem

    damijanv

      I am trying to send mail from an session bean on Jboss 4.0.4GA1.

      My mail-service.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE server>
      <!-- $Id: mail-service.xml,v 1.5.6.1 2005/06/01 06:20:43 starksm Exp $ -->



      <!-- ==================================================================== -->
      <!-- Mail Connection Factory -->
      <!-- ==================================================================== -->


      java:/Mail
      nobody
      password

      <!-- Test -->

      <!-- Change to your mail server prototocol -->



      <!-- Change to the user who will receive mail -->


      <!-- Change to the mail server -->


      <!-- Change to the SMTP gateway server -->


      <!-- Change to the address mail will be from -->


      <!-- Enable debugging output from the javamail classes -->


      jboss:service=Naming





      The code in session bean looks like:

      InitialContext ctx = new InitialContext() ;
      Session mailSession = (Session) ctx.lookup("java:Mail") ;
      Message msg = new MimeMessage(mailSession);
      InternetAddress toAddrs[] = new InternetAddress[1];
      toAddrs[0] = new InternetAddress("damijan@hit.si");
      msg.setRecipients(Message.RecipientType.TO, toAddr);
      msg.setFrom();
      msg.setSubject("Takeoff time.");
      msg.setSentDate(new Date());
      String content = new String("Test");
      msg.setContent(content, "text/plain");
      Transport.send(msg);

      I am getting an error:
      Caused by: java.lang.NoSuchMethodError: javax.activation.DataHandler.(Ljava/lang/Object;Ljava/lang/String;)V
      at javax.mail.internet.MimeMessage.setContent(MimeMessage.java:1380)
      at si.hit.ldap.ejb.session.LdapServerBean.sendMail(LdapServerBean.java:234)


      Thanks in advance,

      Damijan

        • 1. Re: JavaMail problem
          markash

          Good Day,

          Try the following code.

          InitialContext ctx = new InitialContext() ;
          Session mailSession = (Session) ctx.lookup("java:Mail") ;
          Message msg = new MimeMessage(mailSession);
          InternetAddress toAddrs[] = new InternetAddress[1];
          toAddrs[0] = new InternetAddress("damijan@hit.si");
          msg.setRecipients(Message.RecipientType.TO, toAddr);
          msg.setFrom();
          msg.setSubject("Takeoff time.");
          msg.setSentDate(new Date());
          String content = new String("Test");
          msg.setText(content);
          Transport.send(msg);
          

          http://www.javaworld.com/javaworld/jw-10-2001/jw-1026-javamail.html

          Regards,
          Mark P Ashworth


          • 2. Re: JavaMail problem
            damijanv

            Hello again,

            I tried the code you sugessted but I am getting the same exception on msg.setText(String)

            "java.lang.NoSuchMethodError: javax.activation.DataHandler.(Ljava/lang/Object;Ljava/lang/String;)V"

            Best regards,
            Damijan

            • 3. Re: JavaMail problem
              damijanv

              Found the solution. The mail.jar and activation.jar that commes with Jboss 4.0.4 have to be replaced with mail.jar from JavaMail1.4 and activation.jar from jaf1.1. I replaced the jar in server/${config_name}/lib folder.

              Best regards,
              Damijan