1 Reply Latest reply on May 15, 2009 3:29 AM by Stefan Schueffler

    Weird behavior on AS 5 regarding multiple mail sessions

    Leonardo Madrigal Newbie

      On jboss as 4.x was ok to use multiple:

       <mbean code="org.jboss.mail.MailService" name="jboss:service=Whatever">

      on mail-service.xml to define multiple mail sessions.

      On jboss 5 using any *-service.xml that contain multiple Mail Sessions causes jboss to ignore the properties of the first deployed services.


       <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail1">
       <attribute name="JNDIName">mail/Mail1</attribute>
       <attribute name="Configuration">
       <property name="mail.transport.protocol" value="smtp"/>
       <property name="mail.smtp.host" value=""/>
       <mbean code="org.jboss.mail.MailService" name="jboss:service=Mail2">
       <attribute name="JNDIName">mail/Mail2</attribute>
       <attribute name="Configuration">
       <property name="mail.transport.protocol" value="smtp"/>
       <property name="mail.smtp.host" value=""/>


      The services get deployed just fine, and the JNDI lookups return correctly (a mail session)

      but a simple jsp with the following code:
      Context initCtx = new InitialContext();
      Context envCtx = (Context) initCtx.lookup("");
      Object objref = envCtx.lookup("mail/Mail1");
      Session s = (Session) PortableRemoteObject.narrow(objref, Session.class);
      Object objref2 = envCtx.lookup("mail/Mail2");
      Session s2 = (Session) PortableRemoteObject.narrow(objref2, Session.class);

      shows that the properties of the first session (s1) to be the same of s2
      (the SMTP is always

      If the mbean's are separated on diferent -service.xml files, the behavior is the same.

      any ideas?

        • 1. Re: Weird behavior on AS 5 regarding multiple mail sessions
          Stefan Schueffler Newbie


          as i'm facing the same problem, here some more informations:

          Deploying of multiple MailService-mbeans seems working fine: twiddle.sh or the jmx-console shows the right values in the respective MailServices.

          The problem occurs during runtime, when one obtains a javax.mail.Session from the JNDI-Context. Now, this Session always is initialized with the values of the last mailservice deployed, regardless of which jndi-name is used to retrieve this mailsession.

          This error could be related to https://jira.jboss.org/jira/browse/JBAS-5896, as there is a "sharedSession" mentioned. In my opinion, it should not matter if this sharedSession is enabled or disabled by default, as we should have one sharedSession _per registered mbean_ (i do not know if the sharedSession mentioned in the bug report is one per server, or one per mail-mbean. One per server would be only useful if you never will use more than one different mailservice.

          I filed a jboss bug report, https://jira.jboss.org/jira/browse/JBAS-6923.

          Example to reproduce:
          See post from leonardomadrigal.
          Deploy two or more mailservices. For the sake of this example, deploy them each as individual files.
          Run his example application.

          Touch one of the deployed mailservices.
          Run the example application again. You always will see the properties of the last (just touched) mail-service.

          Workaround: none known yet.