3 Replies Latest reply on Dec 15, 2009 4:34 AM by kapitanpetko

    change mail server at runtime??

    deanhiller2000

      I was looking at the MailSession.java class and it looks like the Session is only created once at creation time and after that, I have no way of changing the mail server again.  Out IT would like the mail server, username, etc. to be configurable via a GUI and when they change it, it should change at runtime without restarting the servers.  Is this at all possible?  I can't figure out how the renderer is using the MailSession object and if I can slip in my own component or something.


      I have not been able to figure out how the Renderer knows to send email in the seam source code...it is very weird...how does it get hooked up.
      thanks,
      Dean

        • 1. Re: change mail server at runtime??
          kapitanpetko

          MailSession is application scoped, so once it is created, it is used until you restart your application. You can try to override it and make it event scoped. Then it should be re-created on every call, and you can read configuration in the @Create method. Mail is actually sent by the UIMessage component, the renderer just gives it kick :). Look at UIMessage.java for details.


          HTH

          • 2. Re: change mail server at runtime??
            deanhiller2000

            How do you override it? We tried many things and even went down the path of reflection but unfortunately, the javax.mail.Session is in the http Session instead of the seam bean otherwise our reflection might have worked :(.  Any ideas how to override?


            thanks,
            Dean

            • 3. Re: change mail server at runtime??
              kapitanpetko

              Well you can try to make event scoped, not 100% sure if this will work though. Something like:


              @Name("org.jboss.seam.mail.mailSession")
              @Install(precedence = APPLICATION, classDependencies = "javax.mail.Session")
              @Scope(EVENT)
              @BypassInterceptors
              public class MyMailSession extends MailSession {
              
               private Session session;
              
               @Create
               public void create() {
                 // read hostname from DB, etc.
                 setupMailSession();
               }
              
               @Unwrap
               public Session getSession() {
                 return session;
               }
              
              }
              



              Or if this fails, keep it application scoped and do your thing in @Unwarp:


              @Name("org.jboss.seam.mail.mailSession")
              @Install(precedence = APPLICATION, classDependencies = "javax.mail.Session")
              @Scope(APPLICATION)
              @BypassInterceptors
              public class MyMailSession extends MailSession {
              
               @Unwrap
               public Session getSession() {
                 return createSession();
               }
              
              }
              



              Should be effectively the same thing -- every time you render UIMessage you should get a new session, configured any way you like.
              All this is off the top of my head, so beware :)


              HTH