7 Replies Latest reply on Feb 10, 2010 4:42 AM by Angel Ivanov

    Create mail services

    Angel Ivanov Newbie
      How can deploy more than one mail service in JBoss AS 5.1. When I install JBoss there is one default mail service bound to java:/Mail JNDI name. I want to use one service for sending emails and another for checking emails.
        • 1. Re: Create mail services
          Peter Johnson Master
          I haven't tried this, but you could make a copy of mail-service.xml (as outbound-mail-service.xml, for example) and change the JNDName attribute to be something else, such a java:/OutboundMail. And of course change any other relevant attributes. Then you can look up that one for sending mail and the original one for checking mail.
          • 2. Re: Create mail services
            Angel Ivanov Newbie

            OK. I try this, but there is a problem! When I lookup javax.mail.Session from ENC only first deployed mail session is returned.

             

            1.) out-mail-service.xml:

             

            <?xml version="1.0" encoding="UTF-8"?>
            <server>

              <mbean code="org.jboss.mail.MailService"
                     name="jboss:service=OutMail">
                <attribute name="JNDIName">java:/OutMail</attribute>
                <attribute name="User">user1</attribute>
                <attribute name="Password">password1</attribute>
                <attribute name="Configuration">
                  <configuration>
                    <property name="mail.transport.protocol" value="smtp"/>
                    <property name="mail.smtp.host" value="pmx.sirma.bg"/>
                    <property name="mail.smtp.auth" value="true"/>
                    <property name="mail.smtp.port" value="587"/>
                    <property name="mail.from" value="some@mail.com"/>

                    <property name="mail.debug" value="true"/>

                  </configuration>
                </attribute>
                <depends>jboss:service=Naming</depends>
              </mbean>

            </server>

             

            2.) in-mail-service.xml

             

            <?xml version="1.0" encoding="UTF-8"?>
            <server>

              <mbean code="org.jboss.mail.MailService"
                     name="jboss:service=InMail">
                <attribute name="JNDIName">java:/InMail</attribute>
                <attribute name="User">user2</attribute>
                <attribute name="Password">password2</attribute>
                <attribute name="Configuration">
                  <configuration>       
                    <property name="mail.store.protocol" value="imap"/>
            <property name="mail.imap.auth.plain.disable" value="false"/>
            <property name="mail.imap.host" value="imap.gmail.com"/>
            <property name="mail.imap.port" value="993"/>
            <property name="mail.imap.socketFactory.class" value="javax.net.ssl.SSLSocketFactory"/>
            <property name="mail.imap.socketFactory.fallback" value="false"/>
            <property name="mail.imap.socketFactory.port" value="993"/>
            <property name="mail.imap.partialfetch" value="false"/>
                    <property name="mail.debug" value="true"/>

                  </configuration>
                </attribute>
                <depends>jboss:service=Naming</depends>
              </mbean>

            </server>

            How to deploy two separate mail services?

            • 3. Re: Create mail services
              Peter Johnson Master
              First use JNDIView (within the jmx console) to verify that both mail service names are there. Then verify that your code is looking up the correct name.
              • 4. Re: Create mail services
                Angel Ivanov Newbie

                OK, I look at in jmx-console, the mail services with their jndi names are there, but when lookup one or another from them context.lookup() return only first deployed javax.mail.Session

                 

                Here is my lookup method:

                 

                public static Session getMail(boolean in) throws NamingException {
                  Session session = null;
                  Context context = new InitialContext();
                  session = (Session) context.lookup(in ? "java:/InMail" : "java:/OutMail");
                  Properties properties = session.getProperties();
                  Set<Object> keys = properties.keySet();
                  for(Iterator<Object> i = keys.iterator(); i.hasNext();){
                   String key = i.next().toString();
                   logger.debug(key + ": " + properties.get(key));
                  }
                  return session;
                }

                I attach two pictures from jmx-console.

                 

                • 5. Re: Create mail services
                  Angel Ivanov Newbie

                  Infact, returned javax.mail.Session instances are different (every lookup return new instance, which is normal behaviout), but their properties are equals!

                  On server start up everithing looks fine.

                  Here is some log:

                   

                  2010-02-09 16:38:09,156 Starting jboss:service=InMail
                  2010-02-09 16:38:09,171 Using properties: {mail.pop3.auth=true, mail.pop3.host=pop3.sirma.bg, mail.debug=true, mail.pop3.port=110, mail.store.protocol=pop3}
                  2010-02-09 16:38:09,171 Mail Service bound to java:/InMail
                  2010-02-09 16:38:09,171 Started jboss:service=InMail

                   

                  2010-02-09 16:38:14,703 Starting jboss:service=OutMail
                  2010-02-09 16:38:14,703 Using properties: {mail.debug=true, mail.from=angel.mandrajiyski@sirma.bg, mail.smtp.port=587, mail.transport.protocol=smtp, mail.smtp.auth=true, mail.smtp.host=pmx.sirma.bg}
                  2010-02-09 16:38:14,703 Mail Service bound to java:/OutMail
                  2010-02-09 16:38:14,703 Started jboss:service=OutMail

                   

                  By default when lookup under java: the container must return new instance every time when you do this (like I know from "JavaEE Platform Specification" : EE.5.2.2Sharing of Environment Entries). May be there is something wrong. Who create the new instances and what properties use for that?

                  • 6. Re: Create mail services
                    Peter Johnson Master

                    Like I said originally, I have never tried it. Based on the log file output, and the jmx console info, it seems to have worked. Feel free to debug the problem and post the soultion.

                     

                    By the way, did you look at the two mail MBean in jmx console and verify that they each had their own settings?

                    • 7. Re: Create mail services
                      Angel Ivanov Newbie

                      In JBoss AS 4.2.2 everithing works perfect! The difference from JBoss AS 5.1.0 is that every lookup return the same instance of javax.mail.Session, obviosly it create instances on mail service deploy and return every time when I lookup them (not new instances). I can't use 4.2.2 because I have existing application with @EJB annotations which doesn't work on it.

                      How can I prompt JBoss 5.1 do not return new instances of javax.mail.Session on every lookup?