4 Replies Latest reply on Mar 23, 2009 11:50 PM by h4tr3d

    Multiple mail sessions

    jonathanztaub

      I'm developing an application that retrieves emails on behalf of clients (from yahoo, gmail, hotmail, etc.). Currently, I'm creating the mail session by myself. I know I can define my mail session in the mail-service.xml file.
      However, I have the following questions:
      * Is it possible to define more than one mail session? If so, how (exact xml elements/syntax)?
      * Is a mail session considered a "heavy" resource that JBoss will manage better for me or is creating mail sessions by myself in the code is just as efficient?

        • 1. Re: Multiple mail sessions
          peterj

          To create a second mail service, try this. Copy mail-service.xml as mail2.service.xml (any name ending in -service.xml will work). Change the mbean name and the JNDIName. Example:

          <mbean code="org.jboss.mail.MailService"
           name="jboss:service=Mail2">
           <attribute name="JNDIName">java:/Mail2</attribute>
           ...
          </mbean>


          Alternately, you could place the above mbean declaration in the existing mail-service.xml file.

          • 2. Re: Multiple mail sessions
            jonathanztaub

            Thanks, I'll try it later on.

            By the way, what is the benefit of having JBoss managing this resource?
            Does it perform some kinda of pooling under the hoods and other optimizations? Or is it equal in performance to creating a mail session in the code and not relying on managed resources?

            • 3. Re: Multiple mail sessions
              jonathanztaub

              Thanks! It worked without any problems.

              • 4. Re: Multiple mail sessions
                h4tr3d

                Hi All,

                We are use JBoss AS 5.0.0 and we have trouble: we create two mail-services but when try get information we got similar data for different jndi.

                config:

                <?xml version="1.0" encoding="UTF-8"?>
                <!-- $Id: mail-service.xml 62349 2007-04-15 16:48:15Z dimitris@jboss.org $ -->
                <server>
                 <mbean code="org.jboss.mail.MailService"
                 name="jboss:service=jcCrm">
                 <attribute name="JNDIName">java:/mail/jcCrm</attribute>
                 <attribute name="Configuration">
                 <configuration>
                 <property name="mail.transport.protocol" value="smtp"/>
                 <property name="mail.user" value="jccrm@greenparts.ru"/>
                 <property name="mail.password" value="<password_1>"/>
                 <property name="mail.smtp.host" value="mail.japancar.ru"/>
                 <property name="mail.smtp.port" value="25"/>
                 <property name="mail.smtp.auth" value="true"/>
                 <property name="mail.from" value="no-replay@greenparts.ru"/>
                 <property name="mail.mime.charset" value="UTF-8"/>
                 <property name="mail.debug" value="true"/>
                 </configuration>
                 </attribute>
                 <depends>jboss:service=Naming</depends>
                 </mbean>
                
                 <mbean code="org.jboss.mail.MailService"
                 name="jboss:service=gp">
                 <attribute name="JNDIName">java:/mail/gp</attribute>
                 <attribute name="Configuration">
                 <configuration>
                 <property name="mail.transport.protocol" value="smtp"/>
                 <property name="mail.user" value="gp@greenparts.ru"/>
                 <property name="mail.password" value="<password_2>"/>
                 <property name="mail.smtp.host" value="mail.japancar.ru"/>
                 <property name="mail.smtp.port" value="25"/>
                 <property name="mail.smtp.auth" value="true"/>
                 <property name="mail.from" value="no-replay@greenparts.ru"/>
                 <property name="mail.mime.charset" value="UTF-8"/>
                 <property name="mail.debug" value="true"/>
                 </configuration>
                 </attribute>
                 <depends>jboss:service=Naming</depends>
                 </mbean>
                </server>


                We use next part of code for getting mail-sessions:
                session1 = (Session) context.lookup("java:/mail/gp");
                 session2 = (Session) context.lookup("java:/mail/jcCrm");
                
                 if (session1 != null) {
                 Properties properties = session1.getProperties();
                 properties.list(out);
                 }
                
                 if (session2 != null) {
                 Properties properties = session2.getProperties();
                 properties.list(out);
                 }
                
                 out.write("<br> sesion1.equals(session2) = " + session1.equals(session2) + " " + "<br>");
                


                It provide next result:
                -- listing properties -- mail.user=gp@greenparts.ru mail.mime.charset=UTF-8 mail.transport.protocol=smtp mail.smtp.host=mail.japancar.ru mail.debug=true mail.from=no-replay@greenparts.ru mail.smtp.port=25 mail.smtp.auth=true mail.password=<pass_1>
                
                -- listing properties -- mail.user=gp@greenparts.ru mail.mime.charset=UTF-8 mail.transport.protocol=smtp mail.smtp.host=mail.japancar.ru mail.debug=true mail.from=no-replay@greenparts.ru mail.smtp.port=25 mail.smtp.auth=true mail.password=<pass_1>
                sesion1.equals(session2) = false
                


                So, we can see, that for two different jndi we got similar values. Also, this code work fine on JBoss AS 4.2.3.GA

                Any ideas?