3 Replies Latest reply on Dec 28, 2012 6:12 AM by guinotphil

    Java Mail: timeout configuration, and default session

    guinotphil Apprentice

      Hello,

       

      In my environment I came with some sockets problem with my SMTP server. After some investigations, I found out that the default timeout in Java Mail to a server is -1 (no timeout). Though, the timeout is meant to be configurable with the following properties:

      • mail.smtp.timeout
      • mail.smtp.connectiontimeout
      • mail.pop3.timeout
      • mail.pop3.connectiontimeout
      • mail.imap.timeout
      • mail.imap.connectiontimeout
      • mail.imap.connectionpooltimeout

       

      Although, there is no way to configure these values with the Mail Subsystem. I’ve looked at the code of the class org.jboss.as.mail.extension.MailSessionService, and I didn’t find any references to these properties. Therefore, my only way was to no longer use the Mail subservice, and initialize by myself the Java Mail session in JNDI at startup (I used a Seam component for this job).

       

      Wouldn’t it be nice then if we’d be able to set the timeout, or even any king of properties mail.<protocol>.property in the definition of the Java Mail Session ?

       

      <subsystem xmlns="urn:jboss:domain:mail:1.0">

          <mail-session jndi-name="java:jboss/mail/Default">

              <smtp-server outbound-socket-binding-ref="mail-smtp">

                  <property name="timeout" value="60000" />

                  <property name="connectiontimeout" value="60000" />

              </smtp-server>

              <pop3-server outbound-socket-binding-ref="mail-pop">

                  <property name="timeout" value="60000" />

                  <property name="connectiontimeout" value="60000" />

              </pop3-server>

              <imap-server outbound-socket-binding-ref="mail-imap">

                  <property name="timeout" value="60000" />

                  <property name="connectiontimeout" value="60000" />

                  <property name="connectionpooltimeout" value="60000" />

              </imap-server>

          </mail-session>

      </subsystem>

       

      Also, as a side note, while we can create as much session as we want into JNDI, I realized that some component rely not on a JNDI session, but on the DefaultInstance of Java Mail Session. And that session relies on the settings that were given at the call of getDefaultInstance (though, they can be overridden with getProperties()).

      To avoid these problems, I actually took care in my startup component which create my Java Mail Sessions to ensure that my ‘default’ session is not initialized with Session.getInstance() but with Session.getDefaultInstance(). And then I also bind it on JNDI.

      Wouldn’t it possible to add an attribute in the Mail Subsystem to allow one (and only one) session to be the default JavaMail sessions? The session would have to be set at startup to ensure it is initialized with the correct parameters.

      <subsystem xmlns="urn:jboss:domain:mail:1.0">

          <mail-session jndi-name="java:jboss/mail/Default" default="true">

              <smtp-server outbound-socket-binding-ref="mail-smtp">

                  <property name="timeout" value="60000" />

                  <property name="connectiontimeout" value="60000" />

              </smtp-server>

          </mail-session>

          <mail-session jndi-name="java:jboss/mail/MailboxClient">

              <pop3-server outbound-socket-binding-ref="mail-pop" />

              <imap-server outbound-socket-binding-ref="mail-imap" />

          </mail-session>

          <mail-session jndi-name="java:jboss/mail/OtherSmtp">

              <smtp-server outbound-socket-binding-ref="mail-smtp-bis">

          </mail-session>

      </subsystem>

       

      These are probably not major issues on AS 7, but it’s a bit of a shame as I like the software and sadly I can’t rely on the Mail subsystem anymore.

       

      Regards,

       

      Philippe