2 Replies Latest reply on Nov 19, 2003 9:38 PM by mferreg

    mail service

    sys user Master

      Hello,
      Can anyone explain or give me an exemple on how to use the mail service (I'm using jboss 3.0.7)
      Thanks.

        • 1. Re: mail service
          Andy Newbie

          In your code you can do something like this ...

          Context initial=new InitialContext();
          javax.mail.Session mail_session=(javax.mail.Session)initial.lookup("java:/comp/env/TheMailSession");

          javax.mail.Message msg=new MimeMessage(mail_session);
          msg.setFrom(new InternetAddress("your_email_address"));
          msg.setHeader("X-Mailer","Your_App_Name");

          InternetAddress[] addrs=new InternetAddress[1];
          addrs[0] = new InternetAddress(recipient_email);
          msg.setRecipients(javax.mail.Message.RecipientType.TO,addrs);
          msg.setSubject(subject);
          msg.setSentDate(new java.util.Date());

          Multipart mp=new MimeMultipart();
          MimeBodyPart part=null;
          part = new MimeBodyPart();
          part.setText(text);
          mp.addBodyPart(part);
          msg.setContent(mp);

          Transport.send(msg);


          and then in the deployment descriptors add a block like this for the bean that uses the mail facilities in ejb-jar.xml
          <resource-ref>
          <res-ref-name>TheMailSession</res-ref-name>
          <res-type>javax.mail.Session</res-type>
          <res-auth>Container</res-auth>
          </resource-ref>

          and in jboss.cmp, you add

          <resource-managers>
          <resource-manager res-class="javax.mail.Session">
          <res-name>TheMailSession</res-name>
          <res-jndi-name>java:Mail</res-jndi-name>
          </resource-manager>
          </resource-managers>

          Simple! PS Dont forget to edit $JBOSS_HOME/server/default/deploy/mail-service.xml and put in the outgoing mail server name etc.

          • 2. Re: mail service
            mferreg Newbie

            When he says jboss.cmp I suppose it refers to META-INF/jboss.xml, I say it because I'm trying what the missage says and I've lost some time finding that file.

            Doing what is said here, I get an error NameNotFoundException: TheMailSession not found.

            Any Idea? I'm using jboss 3.2.1 - tomcat 4.1.24

            Thanks in advanced!